該代碼是基於https://dev.mysql.com/doc/connector-net/en/connector-net-programming-prepared-preparing.htmlC#MySQL的參數化查詢使得多頭成空
public void TableTest(string connectionString)
{
string sqlToCreateTable = @"CREATE TABLE IF NOT EXISTS my_table
(auction_key BIGINT NOT NULL, auction_owner VARCHAR(25), first_seen BIGINT,
PRIMARY KEY(auction_key))";
string sqlInsertOrUpdateAuction = "INSERT INTO my_table (auction_key) VALUES (@my_auc_id); ";
using (MySqlConnection dbConnection = new MySqlConnection(connectionString))
{
dbConnection.Open();
// is the table in the database?
MySqlCommand cmd = new MySqlCommand(sqlToCreateTable, dbConnection);
cmd.ExecuteNonQuery();
cmd.Parameters.AddWithValue("@my_auc_id", 123456);
cmd = new MySqlCommand(sqlInsertOrUpdateAuction, dbConnection);
cmd.ExecuteNonQuery();
}
}
的錯誤是123456被視爲無效。
消息=列「auction_key」不能爲空
我試圖改變「嚴格」在的my.ini設置和它沒有什麼區別。
請幫忙。
謝謝你們 - 在添加參數之前加上命令修復它。 – Patrick