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

Autonumber SQL database null problems

P: 27
I'm working in 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
  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")
  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
Share this Question
Share on Google+
1 Reply

P: 27
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

Post your reply

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