473,698 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Ta bles("tControls ").NewRow()

rRow("ctlType") = iControl.GetTyp e.Name

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

Me.DataSet31.Ta bles("tControls ").Rows.Add(rRo w)

Next

Thanks,

hugh
Nov 21 '05 #1
3 3221
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.Ta bles("tControls ").NewRow()

rRow("ctlType") = iControl.GetTyp e.Name

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

Me.DataSet31.Ta bles("tControls ").Rows.Add(rRo w)

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****@newsgro up.nospam> schreef in bericht
news:eH******** *******@tk2msft ngp13.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.Ta bles("tControls ").NewRow()

rRow("ctlType") = iControl.GetTyp e.Name

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

Me.DataSet31.Ta bles("tControls ").Rows.Add(rRo w)

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****@discuss ions.microsoft. com> wrote in message
news:94******** *************** ***********@mic rosoft.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.Ta bles("tControls ").NewRow()

rRow("ctlType") = iControl.GetTyp e.Name

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

Me.DataSet31.Ta bles("tControls ").Rows.Add(rRo w)

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
2405
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 abc 2 abc 3
4
409
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 the following fields: FriendID (AutoNumber) FirstName, LastName and DateOfBirth Please I have tried everything. WOULD BE HIGHLY OBLIGED for HELP Thanks all
8
4327
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. Basically I want to say: If fk_ID is in list then do these statements to that record
8
2081
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", dbOpenTable, dbAppendOnly) I think, some places where I do the same thing to another table it just says "Invalid Operation", I press OK and nothing happens, and I am just
0
2091
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 to the same table. During the simultaneous add and update, a Locked error occurs, and most of the times it locks all the machines. I have been reading on Microsoft Site and on google groups that JET4 and ADO have fix for page locking , which...
1
1122
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 record replaces that last record in the table. Is there a method that I can use to make sure this doesn't happen. The thing is my program was working fine until recently, as I have about 197 records in that table. Can someone please rescue me. this...
0
784
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 primary key auto-increment. If I don't show my primary key column in my datagrid, it won't allow me to add new records (the blank append row at the bottom doesn't appear) Why ?? Thx
0
1156
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 commands dim newdatarow as system.data.datarow newdatarow = <dataset.name>.<table.name>.newrow I put in.. newdatarow = db_ds.tbl_movdb.newrow
1
1498
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 record. (it's an overly complicated attendance policy) Can this be done with a query and SQL or will I have to code in VBA? I am not super proficient in this so any detailed help would be great. I know the syntax for adding records but am not sure...
0
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9161
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8897
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8867
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6522
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.