473,406 Members | 2,217 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,406 software developers and data experts.

SQLDataAdapter Insert Primary Key Issue..

HI:
Can someone tell me HOW to insert a automatic number after my user inserts new data from text boxes into the dataset. I keep getting this error:

Cannot insert the value NULL into column 'id', table; column does not allow nulls. INSERT fails. (ID IS MY KEY)

I can update & delete fine, but when I try to insert, I cannot figure out how to get the primary key inserted. I'm new @ this & I think I've confused myself....
THANK YOU

Dim conn As SqlConnection = GetSQLConnection()

Try
Dim sql As String = "Select * from table"
Dim sa2 As SqlDataAdapter = New SqlDataAdapter(sql, conn)
Try
If dataset.HasChanges Then
sa2.Update(ds, "table")
dataset.AcceptChanges()
End If
Finally
sa2.Dispose()
End Try

Finally
conn.Close()
conn.Dispose()
End Try
Sep 29 '07 #1
1 1885
kenobewan
4,871 Expert 4TB
Why not let sql server do this for you? Then you dont have to insert and avoids possibility of replication.

btw - recommend never using id as a field, even if it doesnt give you an error poor practice.
Sep 30 '07 #2

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

Similar topics

5
by: DraguVaso | last post by:
Hi, I thought it isn't possible to use a SqlDataAdapter and a Databound grid when there isn't a 'real' primary key on the table. Although, is there a way to use it, and define somewhere in the...
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
1
by: Christian Soltenborn | last post by:
Hi experts, I am working on a university project based on VB .NET. I have a connection to MS Access, and I want to insert some data into the database. The sql command INSERT INTO Shoe (Brand,...
10
by: Serdge Kooleman | last post by:
i have a query: select id, name from Dictionary field "id" is guid (so not null, and not identity) i show only "name" in the dataGrid how to set new id when i insert a new record? ...
2
by: Serdge Kooleman | last post by:
i have a query: select id, name from Dictionary field "id" is uniqueidentifier (primary key id is not null, and not identity !) i show only "name" in the dataGrid how to set up new id when i...
1
by: Ranny | last post by:
Question: What is the process to Insert a record using Dataset and SQLDataAdapter? Explanation: Thanks to Cor I am able to get a record to load, modify it, and save it to the database. My...
5
by: Serdge Kooleman | last post by:
i have a query: select id, name from Dictionary field "id" is uniqueidentifier (primary key id is not null, and not identity !) i show only "name" in the dataGrid how to set up new id when i...
8
by: nano2k | last post by:
Hi Shortly, I keep invoices in a table. Occasionally, someone will fire the execution of a stored procedure (SP) that performs several UPDATEs against (potentially) all invoices OLDER than a...
7
by: jthep | last post by:
Hi, I'm a newbie at this but how can I populate a table with data from other tables by using INSERT statements? Below is of what I have so far, I have to populate the PERSON_PROFILE table. I've...
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: 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
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
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...
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.