ADO.NET DataSet.TableName.AddTableNameRow() inserts an extra row
Author |
Message |
Robert Fromon #1 / 3
|
 ADO.NET DataSet.TableName.AddTableName Row() inserts an extra row
I've got a strange problem using ADO.NET. I have a DataSet subclass generated by VisualStudio based on a database table (it was generated by using the Data Form Wizard). The table is called tbl_Agents, and the following lines: objdsAgent.Clear() objdsAgent.tbl_Agents.Addtbl_AgentsRow(newId(), "", "", "","") successfully adds a row to the objdsAgent data set, which I can later save to the database (using OleDbDataAdapter1.Update(ChangedRows), as generated by the wizard). The problem is that after doing this once, the next time I try to add a row and save it to the database, I get an exception saying "Cannot insert value NULL into column 'Id'...". From running Profiler on the database, I can see that ado.net is doing something like the following: INSERT INTO tbl_Agents (Id, FirstName, LastName, CompanyName, Email) VALUES (123,'','','','') INSERT INTO tbl_Agents (Id, FirstName, LastName, CompanyName, Email) VALUES (NULL,NULL,NULL,NULL,NULL) What puzzles me is the second, all NULL row that it's trying to insert (it doesn't do this the first time I add a row, only the second). After the error occurs, the row I was trying to insert has in fact been inserted into the table, so I guess the error is generated by the mystery NULL row. If anybody has seen anything like this, or can shed any light on how to get around it, please let me know. Thanks, Robert Fromont.
|
Sun, 31 Oct 2004 16:50:53 GMT |
|
 |
David branc #2 / 3
|
 ADO.NET DataSet.TableName.AddTableName Row() inserts an extra row
check your commandInsert Statment
Quote: > I've got a strange problem using ADO.NET. > I have a DataSet subclass generated by VisualStudio based on a database > table (it was generated by using the Data Form Wizard). The table is called > tbl_Agents, and the following lines: > objdsAgent.Clear() > objdsAgent.tbl_Agents.Addtbl_AgentsRow(newId(), "", "", "","") > successfully adds a row to the objdsAgent data set, which I can later save > to the database (using OleDbDataAdapter1.Update(ChangedRows), as generated > by the wizard). > The problem is that after doing this once, the next time I try to add a row > and save it to the database, I get an exception saying "Cannot insert value > NULL into column 'Id'...". From running Profiler on the database, I can see > that ado.net is doing something like the following: > INSERT INTO tbl_Agents (Id, FirstName, LastName, CompanyName, Email) VALUES > (123,'','','','') > INSERT INTO tbl_Agents (Id, FirstName, LastName, CompanyName, Email) VALUES > (NULL,NULL,NULL,NULL,NULL) > What puzzles me is the second, all NULL row that it's trying to insert (it > doesn't do this the first time I add a row, only the second). After the > error occurs, the row I was trying to insert has in fact been inserted into > the table, so I guess the error is generated by the mystery NULL row. > If anybody has seen anything like this, or can shed any light on how to get > around it, please let me know. > Thanks, > Robert Fromont.
|
Mon, 01 Nov 2004 01:03:04 GMT |
|
 |
Robert Fromon #3 / 3
|
 ADO.NET DataSet.TableName.AddTableName Row() inserts an extra row
It contains one INSERT statement, and a SELECT too. In addition, the first record inserted doesn't do the additional null INSERT, only susequent records do this. Robert.
Quote: > check your commandInsert Statment
> > I've got a strange problem using ADO.NET. > > I have a DataSet subclass generated by VisualStudio based on a database > > table (it was generated by using the Data Form Wizard). The table is > called > > tbl_Agents, and the following lines: > > objdsAgent.Clear() > > objdsAgent.tbl_Agents.Addtbl_AgentsRow(newId(), "", "", "","") > > successfully adds a row to the objdsAgent data set, which I can later save > > to the database (using OleDbDataAdapter1.Update(ChangedRows), as generated > > by the wizard). > > The problem is that after doing this once, the next time I try to add a > row > > and save it to the database, I get an exception saying "Cannot insert > value > > NULL into column 'Id'...". From running Profiler on the database, I can > see > > that ado.net is doing something like the following: > > INSERT INTO tbl_Agents (Id, FirstName, LastName, CompanyName, Email) > VALUES > > (123,'','','','') > > INSERT INTO tbl_Agents (Id, FirstName, LastName, CompanyName, Email) > VALUES > > (NULL,NULL,NULL,NULL,NULL) > > What puzzles me is the second, all NULL row that it's trying to insert (it > > doesn't do this the first time I add a row, only the second). After the > > error occurs, the row I was trying to insert has in fact been inserted > into > > the table, so I guess the error is generated by the mystery NULL row. > > If anybody has seen anything like this, or can shed any light on how to > get > > around it, please let me know. > > Thanks, > > Robert Fromont.
|
Mon, 01 Nov 2004 14:26:48 GMT |
|
|
|