473,395 Members | 1,941 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,395 software developers and data experts.

Autonumber SQL database null problems

I'm working in VB.net 2005.

I am trying to write some rows from one table onto a second table. The ID field in the original table is an autonumber, the field in the second table is just a regular integer. The code I've written copies all of the information over including the value of the ID field.

When I display the new table in datagridview, I can see that for all nine rows of the new field there is a value in the ID field. However, when I go to update the database, I'm told that "Cannot insert the value NULL into column 'ID', table tables.dbo.NewTable'; column does not allow nulls. INSERT fails."

Here is an example of my code

Expand|Select|Wrap|Line Numbers
  1. For i As Integer = 0 To Table.Rows.Count - 1
  2.                 Dim row1 As DataRow 'Initialized row
  3.                 row1 = .NewTable.NewNewTableRow() 'Tells the program what table the row will belong to
  4.  
  5.                 'Fills in user information into the imaginary row
  6.                 row1("ID") = .Table.Rows(i).Item("ID")
  7.                 row1("Description") = .Table.Rows(i).Item("Description")
  8.                 row1("Note") = .Tabler.Rows(i).Item("Note")
  9.                 row1("StartDate") = .Table.Rows(i).Item("StartDate")
  10.                 row1("EndDate") = .Table.Rows(i).Item("EndDate")
  11.                 row1("Term") = .Table.Rows(i).Item("Term")
  12.                 row1("Contact") = .Table.Rows(i).Item("Contact")
  13.                 row1("ContactType") = .Table.Rows(i).Item("ContactType")
  14.                 row1("OwnerID") = .Table.Rows(i).Item("OwnerID")
  15.  
  16.  
  17.                 .NewTable.Rows.Add(row1)
  18.             Next
  19.             NewTableTableAdapter.Update(.NewTable)

Has anyone seen anything like this, or have any ideas on what could be causing this. As far as I can tell, there are no null values for ID.
Jul 1 '08 #1
1 1230
Ok, now I feel sheepish and somewhat relieved. I had changed the ID field from an autonumber to a regular number. Because the program was giving me brand new errors I didn't think about refreshing my database connection. Once I did. The errors - or at least that one - disappeared. Thanks to all who read this.
Jul 1 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: JW | last post by:
Hi, This is really weird... I have a database that has an autonumber field. Records 1-70 were deleted. Various things have changed to the front end and a few extra fields added to the table. ...
12
by: deko | last post by:
Is there a way to reset the AutoNumber sequence? I have several tables that use the AutoNumber field as the Primary Key, and I'd like to somehow do an Import/Export that will make remove the...
33
by: Lee C. | last post by:
I'm finding this to be extremely difficult to set up. I understand that Access won't manage the primary key and the cascade updates for a table. Fine. I tried changing the PK type to number and...
1
by: BT Openworld | last post by:
I've just had to upgrade to Access 2003. Our company's main sales database started in Access V1.0 and has progressed through V2.0 and 97 without problems. I've converted it to 2003 format and have...
3
by: Megan | last post by:
hello everybody- i'm normalizing a database i inherited. i'm breaking up a huge table named case into several smaller tables. i am creating several many to many relationships between the new...
35
by: Traci | last post by:
If I have a table with an autonumber primary key and 100 records and I delete the last 50 records, the next record added would have a primary key of 101. Is there any way to have the primary key...
26
by: jimfortune | last post by:
Sometimes I use Autonumber fields for ID fields. Furthermore, sometimes I use those same fields in orderdetail type tables. So it's important in that case that once an autonumber key value is...
6
by: HS1 | last post by:
Hello I have a table in Access Database. This table has a AutoNumber field. I use a DataGrid to show that table When I insert a new record in for this table using a DataGrid, there is a...
11
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.