Data is not inserting into table?

前端 未结 5 1096
轮回少年
轮回少年 2020-12-11 11:02

My table name is Customer. It has four columns

CustomerId
CustomerName
CustomerAddress
PhoneNo

This is my c# code. I am not ge

5条回答
  •  温柔的废话
    2020-12-11 11:43

    You didnt specify the same paramets, (forgot to add "@" do it like:

    string query = "insert into Customer(CustomerName,CustomerAddress,PhoneNo) values (@CustNm,'@CustAdd',@Ph)";
            SqlCommand myCommand = new SqlCommand(query,myConnection);
            myCommand.Parameters.AddWithValue("@CustNm",Print[0].CustomerName);
            myCommand.Parameters.AddWithValue("@CustAdd",Print[0].Address);
            myCommand.Parameters.AddWithValue("@Ph",Print[0].Telephone);
    

提交回复
热议问题