E
Eric Kiernan
I'm having problems from c# with an access ( 2003 ) mdb file. It blows
up with a "Data Type mismatch in criteria" when i execute the command
to add a record to a table. It is when MonthBegin, which is a byte is
part of the insert command. It works if I omit MonthBegin. It reads
from the Access file as a byte ( i once cast it to an object to confirm
it was a byte), though, and it is defined in Access as a byte.
Ironically, it does fill the MonthBegin field in the mdb table
accurately. Below is the code. I'm using the OLEDB provider
stringCommand = "INSERT INTO BudgetSpending ( BudgetYear,
Account,MonthToBegin) "
stringCommand += "VALUES (@BudgetYear,@Account,@MonthToBegin)";
objCommand.Parameters.AddWithValue("@BudgetYear", "2009"); // string
objCommand.Parameters.AddWithValue("@Account", tempRow.Account); //string
objCommand.Parameters.AddWithValue("@MonthToBegin", tempRow.MonthToBegin
) // byte.
objCommand.CommandText = stringCommand;
objCommand.CommandType = CommandType.Text;
objConnection.Open();
objCommand.ExecuteNonQuery(); // BLOWS WITH THE DATA TYPE MISMATCH ERROR
the insert command looks like this in the debugger
"INSERT INTO BudgetSpending ( BudgetYear, Account,MonthToBegin) VALUES
(@BudgetYear,@Account,@MonthToBegin)"
the same thing happens if i don't use parameters and use the object
fields directly.
up with a "Data Type mismatch in criteria" when i execute the command
to add a record to a table. It is when MonthBegin, which is a byte is
part of the insert command. It works if I omit MonthBegin. It reads
from the Access file as a byte ( i once cast it to an object to confirm
it was a byte), though, and it is defined in Access as a byte.
Ironically, it does fill the MonthBegin field in the mdb table
accurately. Below is the code. I'm using the OLEDB provider
stringCommand = "INSERT INTO BudgetSpending ( BudgetYear,
Account,MonthToBegin) "
stringCommand += "VALUES (@BudgetYear,@Account,@MonthToBegin)";
objCommand.Parameters.AddWithValue("@BudgetYear", "2009"); // string
objCommand.Parameters.AddWithValue("@Account", tempRow.Account); //string
objCommand.Parameters.AddWithValue("@MonthToBegin", tempRow.MonthToBegin
) // byte.
objCommand.CommandText = stringCommand;
objCommand.CommandType = CommandType.Text;
objConnection.Open();
objCommand.ExecuteNonQuery(); // BLOWS WITH THE DATA TYPE MISMATCH ERROR
the insert command looks like this in the debugger
"INSERT INTO BudgetSpending ( BudgetYear, Account,MonthToBegin) VALUES
(@BudgetYear,@Account,@MonthToBegin)"
the same thing happens if i don't use parameters and use the object
fields directly.