在架构3layers中使用linq和存储过程向表添加信息

时间:2014-03-11 08:35:27

标签: asp.net

我在项目中使用存储过程和Linq。我想插入信息的用户是什么代码?

我用3层架构编写我的网站。

我在bll层的代码

public class Account
{
        #region private Account

        private int _ID;
        private string _Name;
        private string _Family;
        private string _Email;
        private string _Tel;
        private string _Username;
        private string _Password;

        #endregion

        #region public property

        public int ID
        {
            get { return _ID; }
            set { _ID = value; }
        }

        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }

        public string Family
        {
            get { return _Family; }
            set { _Family = value; }
        }

        public string Email
        {
            get { return _Email; }
            set { _Email = value; }
        }

        public string Tel
        {
            get { return _Tel; }
            set { _Tel = value; }
        }

        public string Usernamr
        {
            get { return _Username; }
            set { _Username = value; }
        }

        public string Password
        {
            get { return _Password; }
            set { _Password = value; }
        }

        #endregion

        #region public method

        CARDDataContext db = new CARDDataContext(); 

        public void insertAccount()
        {
            db.insertAccount(_Name, _Family, _Email, _Tel, _Username, _Password);
            System.Windows.Forms.MessageBox.Show(" اطلاعات با موفقیت درج شد ");
        }  

        #endregion
}

我的代码插入按钮

protected void Button1_Click(object sender, EventArgs e)
{
    Account account=new Account();

    account.Name = TextBox1.Text; 
    account.Family = TextBox2.Text ;
    account.Email = TextBox3.Text ;
    account.Tel = TextBox4.Text ;
    account.Usernamr = TextBox5.Text;
    account.Password = TextBox6.Text;
    account.insertAccount();

我的项目错误是

  

抛出新的NotImplementedException();

我的存储过程是:

create procedure [dbo].[insertAccount]
(
    @Name nvarchar(50),
    @Family nvarchar(50),
    @Email nvarchar(50),
    @Tel nvarchar(50),
    @Username nvarchar(50),
    @Password nvarchar(50) )
as 
    set nocount on

    insert into Account (Name, Family, Email, Tel, Username, Password)
    values (@Name, @Family, @Email, @Tel, @Username, @Password)

    return

如何以及在何处添加插入帐户方法?

这是插入帐户方法:

public void insertAccount()
{
    db.insertAccount(_Name, _Family, _Email, _Tel, _Username, _Password);
    System.Windows.Forms.MessageBox.Show(" اطلاعات با موفقیت درج شد ");
} 

我添加了插入帐户方法。我的项目有什么问题?

请帮帮我。

1 个答案:

答案 0 :(得分:0)

右键单击insertAccount();并寻找"转到定义"

如果没有定义,意味着没有具有该名称的方法,则您需要创建它。