0
我的代碼會拋出主題中提到的這個錯誤。我不知道起源,因爲使用ODBC連接到它的工作原理,但使用SQL連接到SQL Server Express不起作用。如何解決它?附加信息:'?'附近語法不正確
SqlCommand Command = new SqlCommand("insert into lojas (NIF, Loja, bloqueado, DataFim, lastupdate, Nome) values (?, ?, ?, ?, ?, ?)", connection);
Command.CommandType = CommandType.Text;
Command.Parameters.AddWithValue("@NIF", grid_lic.CurrentRow.Cells[1].Value);
Command.Parameters.AddWithValue("@Loja", grid_lic.CurrentRow.Cells[2].Value);
Command.Parameters.AddWithValue("@Bloqueado", grid_lic.CurrentRow.Cells[3].Value);
Command.Parameters.AddWithValue("@DataFim", grid_lic.CurrentRow.Cells[4].Value);
Command.Parameters.AddWithValue("@lastupdate", grid_lic.CurrentRow.Cells[5].Value);
Command.Parameters.AddWithValue("@Nome", grid_lic.CurrentRow.Cells[6].Value);
connection.Open();
Command.ExecuteNonQuery();
我認爲這是問題,但現在當我插入數據時出現了另一個問題:「無法將值NULL插入列'Id',表'Licenciamento.dbo.lojas';列不允許爲空值。 「。但是,Id在sql server中設置爲自動增量。不應該自動填充到數據網格中嗎? – TFDD