Parameterize SQL query

前端 未结 5 656
Happy的楠姐
Happy的楠姐 2020-12-04 02:35

Many posts about Parameters in SQL with C# but I am still missing something. I am not getting an error message but no data is inserted. What is missing? I have text boxes na

5条回答
  •  Happy的楠姐
    2020-12-04 02:50

    There are many ways of going about it. One of the ways is to replace the lines in the try block with:

    comm.Parameters.AddWithValue("@first", first);
    comm.Parameters.AddWithValue("@last", last);
    comm.Parameters.AddWithValue("@addy", addy);
    comm.Parameters.AddWithValue("@city1", city1);
    comm.Parameters.AddWithValue("@stat", stat);
    comm.Parameters.AddWithValue("@zippy", zippy);
    

    If you do that, you dont need all the SqlParameter initializations

    And you obviously need to execute the command:

    comm.ExecuteNonQuery();
    

提交回复
热议问题