ADO.NET DataSet.TableName.AddTableNameRow() inserts an extra row 
Author Message
 ADO.NET DataSet.TableName.AddTableNameRow() 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  
 ADO.NET DataSet.TableName.AddTableNameRow() 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  
 ADO.NET DataSet.TableName.AddTableNameRow() 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  
 
 [ 3 post ] 

 Relevant Pages 

1. asp.net DataGrid adding an extra Header Row

2. table row text will not show after row insert

3. insert row from row

4. Inserting Rows into a Datagrid connected to an ADO Data source

5. Cant insert row with ADO

6. Inserting Rows into a Datagrid connected to an ADO Data source

7. Cant insert row with ADO

8. Problem inserting a row with ADO and Access2000

9. Reading Excel sheet via ADO.NET skips first row

10. SSDBGrid Unbound - extra row gets loaded

11. Extra blank rows when exporting to Excel

12. Extra row in the table

 

 
Powered by phpBB® Forum Software