Adding records with a Identity Primary Key (no nulls)

H

Hugh O

Hi,

I am not sure if this type of question should be raised in this Newsgroup.
If not please direct me.

I am new to using RDO.Net data access but I thought I understood it. The 6
lines of code below is simply trying to load an empty table that has only
three columns. In the code I set the Name and Type fields. The third
column is a unique primary key set to Integer. I have set the Primary Key
to Identity with a seed of 1 and increment of one.

This code is being added to a Visual Basic.Net ASP.Web application under
Visual Studio.Net 2003. I was expecting the primary key to be automatically
initialize with the next unique value.

But I get the following error message:

Column 'ctlUnq' does not allow nulls.
I can easily manually add rows to this table via the SQL Server Enterprise
Manager. It automatically creates that primary key. In fact it will not
allow me to edit or initialize that primary key column. There is something
I do not understand. It sounds like a catch 22. I can't set the column but
I can't leave it null??

I would appreciate any direction.

************************************************

For Each iControl In Me.Controls(1).Controls

rRow = Me.DataSet31.Tables("tControls").NewRow()

rRow("ctlType") = iControl.GetType.Name

If iControl.ID = Nothing Then rRow("ctlName") = "Nothing" Else
rRow("ctlName") = iControl.ID

Me.DataSet31.Tables("tControls").Rows.Add(rRow)

Next

Thanks,

hugh
 
H

Hugh O

Dennis,
Thanks a lot. That is exactly what the problem was. But I am slightly
confused.

I used SQL Enterprise Manager to create the new table. I have used that for
all my tables in this ASP.Net web app. What confused me was that I had
other tables that used this same kind of Identity setting for the primary
key. But they did not have any problem in generating a new row even using
similar code as this problem.

I just checked and those tables have the autoincrement property set to True.
But I do not know what I did that made those tables have a true setting and
this problem table to have a false setting.

Anyway thanks. I now know, thanks to you. What to look for and what to
set. I think that for future new tables I will generate them from code and
make sure this property is set.

Hope you and your family are high and dry in Houston. thanks again.

hugh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top