'必须声明标量变量“@categoryid”。当我尝试使用 dapper 将数据从过程插入到数据库时

我试图通过一个简单的过程将数据插入到我的数据库中,但是当我单击我的按钮时,我不断返回:


'必须声明标量变量“@categoryid”。


我可以补充一点,没有变量的另一个数据添加工作没有问题。


我在哪里犯了错误?


插入类:


public partial class B_Line

{

    public B_Line()

    {

        this.Budget_Scheme = new HashSet<Budget_Scheme>();

    }


    public int Line_id { get; set; }

    public int Category_id { get; set; }

    public string Name { get; set; }

    public string Comment { get; set; }


    public void InsertLine(int categoryID, string name, string comment)

    {

        using (var connection = Connection.ConnectionFactory.GetOpenConnection())

        {

            List<B_Line> lines = new List<B_Line>();

            lines.Add(new B_Line {Category_id = categoryID, Name = name, Comment = comment});

            connection.Execute("dbo.Insert_Line @categoryid, @name, @comment", lines);

        }

    }

}

执行按钮:


private void Button1_Click(object sender, EventArgs e)

{

    B_Line lines = new B_Line();

    int ID_Kategorii = Int32.Parse(categoryID.Text);

    lines.InsertLine(ID_Kategorii, nameLine.Text, commentLine.Text);

}

存储过程 MSSQL:


ALTER procedure [dbo].[Insert_Lines](@categoryid int, @name nchar(40), @comment nchar(100)) as insert into BCategory (Category_id, Name, Comment) Values (@categoryid, @name, @comment)


达令说
浏览 102回答 0
0回答

繁星淼淼

你会在这里找到你需要的所有帮助:https://medium.com/dapper-net/get-started-with-dapper-net-591592c335aa“参数”部分和下面的“存储过程”部分。玩得开心!:)
打开App,查看更多内容
随时随地看视频慕课网APP