InsertParameters.Add doesn't function ainan ASP.NET application

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In my application (ASP.net) I use the following:

MyDataSource.InsertParameters.Clear();
MyDataSource.InsertParameters.Add("AdvID", TypeCode.String, sAdvID);
MyDataSource.InsertParameters.Add("Name", txtName.Text);
MyDataSource.InsertCommand = "INSERT INTO markt.advertizers " +
"(AdvID, Email, Name) VALUES (@AdvID,@Name)";
MyDataSource.Insert();

When I run the app, I get the excheption:
"ERROR [HYT00] [MySQL][ODBC 3.51 Driver][mysqld-5.0.24a-community-nt]Column
'AdvID' cannot be null"

What do I do wrong here (except for using MySQL;-)?
 
This line specifies three column names, but only has two values.

MyDataSource.InsertCommand = "INSERT INTO markt.advertizers " +
"(AdvID, Email, Name) VALUES (@AdvID,@Name)";

Shouldn't it be:

MyDataSource.InsertCommand = "INSERT INTO markt.advertizers " +
"(AdvID, Name) VALUES (@AdvID,@Name)";

Or add Email as a parameter and add it to both sides of the insert
statement.

Ensure that Name is not a reserved word in MySQL.
 
Jim,

To make a clean test I reduced it to the following:
MyDataSource.InsertParameters.Add("AdvID", TypeCode.String, sAdvID);
MyDataSource.InsertCommand = "INSERT INTO markt.advertizers " +
"(AdvID) VALUES (@AdvID)";
MyDataSource.Insert();

The result is the same: "'AdvID' cannot be null".
It looks like the parameter is not passed to the query. I guess, there is
some sort of a syntax error, but can't find where.
 
I found it!
The point is that parameters have to spercified differntly in the query
string, like that:
MyDataSource.InsertCommand = "INSERT INTO markt.advertizers " +
"(AdvID) VALUES (?)";
The qestion mark (?) tells the system to substitute it with a parameter.
 
Back
Top