Why the ExecuteNonQuery catch exception {"validation error for column \"ORGTABLE\".\"FIKEYID\", value \"* null *\""}
string stValuesPlaceHolder = "@p0";
for (int iii = 1; iii < liststFieldValuesNoKeyId.Count; iii++)
stValuesPlaceHolder += ", @p" + (iii).ToString();
FbTransaction fbTransaction = fbConn.BeginTransaction();
FbCommand fbCmd = new FbCommand("INSERT INTO " + stTableName + "(" + stFieldNamesNoKeyId + ") VALUES ( " + stValuesPlaceHolder + " )", fbConn, fbTransaction);
for (int iii = 0; iii < liststFieldValuesNoKeyId.Count; iii++) {
string stPlaceHolder = "@p" + (iii).ToString();
string stValue = liststFieldValuesNoKeyId[iii];
fbCmd.Parameters.AddWithValue(stPlaceHolder, stValue);
}
fbCmd.ExecuteNonQuery();
fbTransaction.Commit();
The stTableName is OrgTable.
The fields names are:
fstPriority, fstInfo, fstDateCreated, fstDateModified, fiKeyID.
The field definitions are:
fstPriority VARCHAR(30), fstInfo VARCHAR(100), fstDateCreated VARCHAR(30), fstDateModified VARCHAR(30), fiKeyID INTEGER PRIMARY KEY
In this section of the code:
stFieldNamesNoKeyId = "fstPriority, fstInfo, fstDateCreated, fstDateModified".
stValuesPlaceHolder = "@p0, @p1, @p2, @p3"
Four fbCmd.Parameters.AddWithValue:
stPlaceHolder = "@p0" ... stValue = "1st value";
stPlaceHolder = "@p1" ... stValue = "2nd value";
stPlaceHolder = "@p2" ... stValue = "3rd value";
stPlaceHolder = "@p3" ... stValue = "4th value";
I did not add a value for fiKeyID as it as the PRIMARY KEY.