Home All Groups Group Topic Archive Search About

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

Author
26 Oct 2006 1:01 PM
Roland
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;-)?

Author
26 Oct 2006 2:31 PM
Jim Hughes
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.

Show quote
"Roland" <Rol***@discussions.microsoft.com> wrote in message
news:26146C53-CC20-4D3A-88D0-C4BB7D88D4F6@microsoft.com...
> 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;-)?
>
Author
27 Oct 2006 8:06 AM
Roland
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.
Author
27 Oct 2006 8:49 AM
Roland
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.

AddThis Social Bookmark Button