473,387 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Adding records with a Identity Primary Key (no nulls)

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
3 3203
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jamie Fryatt | last post by:
Hi everyone, here's what id like to do. I have a table with 2 fields, name and value I need to be able to add multiple records quickly, for example I need to add name value abc 1...
4
by: Manish Sawjiani | last post by:
Hi Experts, I am just into dot net and i want simple code for adding records into Access table (97) using oledb. There are no queries in the databases and there is only one table: Friends with...
8
by: tom | last post by:
I am new to SQL administration. >From a list of IDs that are the primary key in one table (i.e. Customer Table), I want to make changes in tables that use those IDs as a foreign key. ...
8
by: k | last post by:
Hi all I split a database in a table-part and a all-the-rest-part and linked the tables, but my code adding records to a table crashes on Set rs = db.OpenRecordset("tblDeltakelse",...
0
by: brijeshmathew | last post by:
Hi I use Visual Basic 6, Service Pack 6, Microsoft ActiveX Data Objects 2.8 Library(msado15.dll) and access 2000 database using JET 4 OLE. I have an application that adds records simultaneously...
1
by: Nkagi | last post by:
Hi All, I have a problem of adding records into table, if the cursor is on the first record the record that I add replaces the first record and then I moved it to the last record and the new...
0
by: Sam | last post by:
Hi, I have a datagrid with two columns filled from a dataset that is linked to a table of my database. That tables has 2 columns which corresponds to the one displayed in my datagrid + 1 column...
0
by: Mustang97 | last post by:
I've created a custom datagrid with a custom ado connection. Everything works perfectly except now I am trying to add a button that will add records. The way I know how to do that is with the...
1
by: Kristilee | last post by:
I am working with an attendance database that holds records for each employee for when they are absent. For every 30 days WORKED for each employee I need to have the database automatically add a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.