By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

Adding records with a Identity Primary Key (no nulls)

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Set it to "AutoIncrement", not Unique
--
Dennis in Houston
"Hugh O" wrote:
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

Nov 21 '05 #2

P: n/a
Hugh,

Try to use the Guid for your unique identifier, autoincrement will need you
to handle all kind of problems (getting the keys back in a
dataset/datatable).

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps,

Cor

"Hugh O" <Hu****@newsgroup.nospam> schreef in bericht
news:eH***************@tk2msftngp13.phx.gbl...
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

Nov 21 '05 #3

P: n/a
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
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:94**********************************@microsof t.com...
Set it to "AutoIncrement", not Unique
--
Dennis in Houston
"Hugh O" wrote:
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

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.