My table name is Customer
. It has four columns
CustomerId
CustomerName
CustomerAddress
PhoneNo
This is my c# code. I am not getting any exceptions and data is not inserting into database.
string connString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\VictoryDatabase.mdf;Integrated Security=True;User Instance=True";
SqlConnection myConnection = new SqlConnection(connString);
try
{
myConnection.Open();
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);
Console.WriteLine(Print[0].Telephone);
myCommand.ExecuteNonQuery();
myConnection.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…