将数据插入数据库

时间:2010-04-22 19:03:03

标签: .net sql-server

所以我正在创建一个“基本”登录文件,其中一个人登录,并且该人在该表单上输入的数据被转移到另一个表单,即我的数据库/表。

我认为问题在这里,但我会发布剩下的代码。

CREATE FUNCTION dbo.Function4
 (

 parameter1 int = 5,
 parameter2 datatype

 )
RETURNS Table1 TABLE (UserName, Password, Password_Confirmation, Assets)
AS
 BEGIN
   INSERT INTO Table1
   (UserName, Password, Password_Confirmation, Assets)
   VALUES
   (a,b,c,d);
     /*SELECT ... FROM ...*/
 RETURN
 END

这是登录表

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Login_Basic
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        Form3 Delta = new Form3();

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void Form2_Load(object sender, EventArgs e)
        {
            this.Hide();

        } 

        private void textBox6_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox6_KeyPress(object sender, KeyPressEventArgs e)
        {
            int i = Convert.ToInt32(e.KeyChar);
            if (!(Char.IsDigit(e.KeyChar) || Char.IsControl(e.KeyChar) || (e.KeyChar == '.' && this.Text.Contains(".") == false)))
                e.Handled = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Delta.Show();



            //if (textBox3.Text.Equals(""))
            //{
            //    MessageBox.Show("Please enter your username");
            //}
            //else
            //{
            //    this.Hide();
            //}



           // if (textBox4.Text.Equals(""))
            //{
            //    MessageBox.Show("Please enter your password");

           // }
           // else
            //{
            //    this.Hide();
           // }

           // if (textBox5.Text.Equals(""))
           // {
           //     MessageBox.Show("Please re-enter your password");

           // }
           // else
           // {
           //     this.Hide();
           // }

            //if (textBox6.Text.Equals(""))
            //{
           //     MessageBox.Show("Please enter your amount");
           //     
           // }
           // else
           // {
           //     this.Hide();
           // }



        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Hide();

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }

        private void panel2_Paint(object sender, PaintEventArgs e)
        {
            /*if (textBox3.Text.Equals("") && textBox4.Text.Equals("") && textBox5.Text.Equals("") && textBox6.Text.Equals(""))
            {
                button1.Enabled = false;

            }
            else
            {
                button1.Enabled = true;


            }*/
        }
    }
}

这是我数据库的“Pic”

http://s299.photobucket.com/albums/mm305/krsimms123/Code.jpg

提前致谢(我会每隔几个小时检查一次,以便我可以帮忙解释一下)

2 个答案:

答案 0 :(得分:2)

我的印象是您无法更新或插入TSQL函数中的记录。

See this link

  

用户定义的函数不能用于执行一组操作   修改全局数据库状态。   用户定义的函数,如系统   函数,可以从a调用   查询。它们也可以被执行   通过类似的EXECUTE语句   存储过程。

<强>增加:

您需要使用Meff指出的存储过程。

CREATE PROCEDURE InsertLoginAttempt
    @UserName nvarchar(25)
    @Password nvarchar(25)
AS
    INSERT INTO Table1 (UserName, Password)
    VALUES (@UserName, @Password)

有关如何从.net

调用存储过程的信息,请参阅this link

答案 1 :(得分:0)

你的功能是插入(a,b,c,d)?

CREATE FUNCTION dbo.Function4( )
RETURNS Table1 TABLE (UserName, Password, Password_Confirmation, Assets)
AS
 BEGIN
   SELECT UserName, Password, Password_Confirmation, Assets FROM Table1
   RETURN
 END