What is the correct way to form a parameterized SQL statement in C#

后端 未结 2 404
情书的邮戳
情书的邮戳 2021-01-24 17:08

Objective: Using C# and SQL2008 correctly setup a Parameterized SQL Insert statement

Issue: The following statement is used in a for lo

2条回答
  •  萌比男神i
    2021-01-24 17:38

    You don't have to re-declare the variable inside the SQL code. This should work:

    sql =
        "INSERT INTO " +
            "database.dbo.table" +
                "(database.dbo.tabe.RowName) " +
        "VALUES " +
            "(@RowName) ";
    
    cmd.CommandText = sql;
    cmd.Parameters.AddWithValue("@RowValue ", Row.RowName);
    

提交回复
热议问题