我想從用戶的數據表插入數據。我得到這個異常:「異常:在事務附近的語法不正確」。我試圖找到語法錯誤,但我無法解決它。如何解決「交易」附近的錯誤語法?
public void Add_to_Transaction(SqlConnection conn , int serial_number , DataTable dt)
{
try
{
//DataTable dt = new DataTable();
SqlCommand cmd1 = new SqlCommand();
cmd1.Connection = conn;
cmd1.CommandText = "SELECT * FROM Transaction";
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = cmd1;
adapter.Fill(dt);
SqlParameter serial_number1 = new SqlParameter("product_id",serial_number);
SqlParameter quantity = new SqlParameter("quantity", 0);
SqlParameter date = new SqlParameter("date", DateTime.Today);
cmd1.Parameters.Add(serial_number1);
cmd1.Parameters.Add(quantity);
cmd1.Parameters.Add(date);
Console.WriteLine("111111111111111111");
cmd1.CommandText = "INSERT INTO Transaction (quantity,date,product_id) VALUES (@quantity,@date,@product_id)";
cmd1.ExecuteNonQuery();
Console.WriteLine("222222222222222222");
cmd1.Parameters.Clear();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
「Tatabransaction」?你在這裏或在你的程序中輸入錯了嗎? – tnw 2013-04-11 20:07:23
大海撈針出現在腦海中......什麼原因導致了錯誤? – Sayse 2013-04-11 20:07:53
你有一個流浪'之前@product_id – 2013-04-11 20:08:36