我正在尝试将这些数据插入到我的数据库表中,但它无法正常工作。有错误表示关键字'Set'附近的语法不正确。实际上这是什么错误?无法知道如何处理这个
//insert clientID into traderecords.
SqlCommand sqlinsertCmd = new SqlCommand("INSERT TradeRecords Set ClientID = @clientID", hookUp7);
sqlinsertCmd.Parameters.Add("@clientID", SqlDbType.Int).Value = clientID;
sqlinsertCmd.ExecuteNonQuery();
//insert stockname into traderecords.
SqlCommand sqlinsertCmd2 = new SqlCommand("INSERT TradeRecords Set StockName = @stockname", hookUp8);
sqlinsertCmd2.Parameters.Add("@stockname", SqlDbType.Int).Value = stockname;
sqlinsertCmd2.ExecuteNonQuery();
//insert amount of unit into traderecords.
SqlCommand sqlinsertCmd3 = new SqlCommand("INSERT TradeRecords Set Amount = @amountofunit", hookUp9);
sqlinsertCmd3.Parameters.Add("@amountofunit", SqlDbType.Int).Value = amountofunit;
sqlinsertCmd3.ExecuteNonQuery();
//insert total price into traderecords.
SqlCommand sqlinsertCmd4 = new SqlCommand("INSERT TradeRecords Set TotalPrice = @answer", hookUp10);
sqlinsertCmd4.Parameters.Add("@answer", SqlDbType.Int).Value = answer;
sqlinsertCmd4.ExecuteNonQuery();
//insert current date into traderecords.
SqlCommand sqlinsertCmd5 = new SqlCommand("INSERT TradeRecords Set CurrentDate = @datetime", hookUp11);
sqlinsertCmd5.Parameters.Add("@datetime", SqlDbType.Int).Value = datetime;
sqlinsertCmd5.ExecuteNonQuery();
//insert price per unit into traderecords.
SqlCommand sqlinsertCmd6 = new SqlCommand("INSERT TradeRecords Set PricePerUnit = @stockpriceperunit", hookUp12);
sqlinsertCmd6.Parameters.Add("@stockpriceperunit", SqlDbType.Int).Value = stockpriceperunit;
sqlinsertCmd6.ExecuteNonQuery();
//insert payment type into traderecords.
SqlCommand sqlinsertCmd7 = new SqlCommand("INSERT TradeRecords Set PaymentType = 'Buy'", hookUp13);
sqlinsertCmd7.Parameters.Add("Buy", SqlDbType.Int).Value = "Buy";
sqlinsertCmd7.ExecuteNonQuery();
//insert client nameinto traderecords.
SqlCommand sqlinsertCmd8 = new SqlCommand("INSERT TradeRecords Set ClientName = @clientname", hookUp14);
sqlinsertCmd8.Parameters.Add("@clientname", SqlDbType.Int).Value = clientname;
sqlinsertCmd8.ExecuteNonQuery();
答案 0 :(得分:1)
您的插入语法错误
将此语法应用于所有语句
SqlCommand sqlinsertCmd = new SqlCommand("INSERT TradeRecords(ClientID)
values(@clientID)";
sqlinsertCmd.Parameters.Add("@clientID", SqlDbType.Int).Value = clientID;
sqlinsertCmd.ExecuteNonQuery();