If your table name or column names includes white space, you need to use them with square brackets like [Asset Status]
. But this is not recommended. Would be better changing your column name to something else if you can.
Read: Database, Table and Column Naming Conventions?
Also use using
statement to dispose your database connections and objects.
using(SqlCeCommand cmd = Login.sqlConn.CreateCommand())
{
cmd.CommandText = "INSERT INTO tbl_AStatus ([Asset Status],Remarks) VALUES (@a, @b)";
cmd.Parameters.Add("@a", SqlDbType.NVarChar).Value = txtAssetStatus.Text;
cmd.Parameters.Add("@b", SqlDbType.NVarChar).Value = txtRemarks.Text;
// I assume your column types are NVarChar
Login.sqlConn.Open();
int a = cmd.ExecuteNonQuery();
MessageBox.Show(a.ToString());
}
And don't use AddWithValue
method. It may generate unexpected results sometimes. Use SqlParameterCollection.Add
method and it's overloads.
Read: Can we stop using AddWithValue()
already?