Inserting data with .net IDbCommand and IDbDataParameter

So, i have the following code:

IDbCommand masterMeterCommand = dbConn.CreateCommand();
masterMeterCommand.CommandText = "insert into metermaster (MeterId, UtilityId, ManufacturerId) values (@MeterId,2,1)";

IDbDataParameter dbIdParam = masterMeterCommand.CreateParameter();
dbIdParam.ParameterName = "@MeterId";
dbIdParam.Value = 1;


It always fails at ExecuteNonQuery with a "Column 'MeterId' cannot be null". So it seems that the parameter is not being populated or something. If i execute:

insert into metermaster (MeterId, UtilityId, ManufacturerId) values (1,2,1)

then it works just fine...what gives?

Who is Participating?
EE_AutoDeleterConnect With a Mentor Commented:
Because you have presented a solution to your own problem which may be helpful to future searches, this question is now PAQed and your points have been refunded.

MarkoBarkoAuthor Commented:
Never mind, answered my own question...

the syntax for the prepared statement differs depending on the underlying provider.

The syntax above works on MS SQL which uses the @ symbol to mark variables...i was using the MySQL provider which uses question marks for the same purpose...

So much for writing portable queries...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.