|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
InsertParameters.Add doesn't function ainan ASP.NET applicationIn 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. 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;-)? > 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. |
|||||||||||||||||||||||