|
-
Jul 26th, 2015, 12:58 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] Add row to SQL Server table with Primary Key ID field using Identity Specification
I created a simple table with an ID field and text string field. The ID field is Primary Key integer and set the Identity specification so as to auto increment the ID. I then used the Data Source Configuration wizard to create a strongly typed DataSet in the project. But now I can't figure out how to add a row to the table. If I don't include a value in the ID column I get a null exception. How do I do this properly?
vb.net Code:
Using taTestMe As New TestMeDataSetTableAdapters.ErrorsTableAdapter, dtErrors As New TestMeDataSet.ErrorsDataTable
Dim drNew As TestMeDataSet.ErrorsRow
drNew = dtErrors.NewErrorsRow
'drNew.ID = 1
drNew.Message = "Test 3"
dtErrors.Rows.Add(drNew)
taTestMe.Update(dtErrors)
End Using
Thank you for taking the time to read my post.
-
Jul 26th, 2015, 01:36 PM
#2
Re: Add row to SQL Server table with Primary Key ID field using Identity Specificatio
My guess is that your not working with the database that you think you are. If you added the database to your project and the IDE is in Debug mode, check the database in the "bin\debug" folder. Because if the "ID" field is an Identity field and autonumber, then your code should work fine.
-
Jul 26th, 2015, 01:48 PM
#3
Thread Starter
Frenzied Member
Re: Add row to SQL Server table with Primary Key ID field using Identity Specificatio
Roger. I'll start over from scratch. Am I creating the DataSet correctly by using that wizard?
-
Jul 26th, 2015, 01:59 PM
#4
Thread Starter
Frenzied Member
Re: Add row to SQL Server table with Primary Key ID field using Identity Specificatio
It wasn't that I wasn't connecting to a different database but that was the clue I needed to solve the problem. The initial table design had no identity specification and I created the DataSet using the wizard. After I change it to auto-increment I ran the wizard again but failed to create a new string. In my old DataSet I can see the AutoIncrement was false. This time I had it create a new connection string and my code works now. Thank you much for heading me in the right direction.
-
Jul 26th, 2015, 02:22 PM
#5
Re: [RESOLVED] Add row to SQL Server table with Primary Key ID field using Identity S
When using datasets created by the Wizard from a database, when you modify the database, sometimes its just best to delete the affected datatable from the dataset and then run the wizard and add it back. There are a few bugs with the wizard and sometimes it doesn't update the dataset correctly.
-
Jul 26th, 2015, 02:24 PM
#6
Thread Starter
Frenzied Member
Re: [RESOLVED] Add row to SQL Server table with Primary Key ID field using Identity S
That's great advice. Thank you. Is it better not to use the Wizard? Is there a manual way that is better?
-
Jul 26th, 2015, 02:45 PM
#7
Re: [RESOLVED] Add row to SQL Server table with Primary Key ID field using Identity S
 Originally Posted by cory_jackson
That's great advice. Thank you. Is it better not to use the Wizard? Is there a manual way that is better?
I use the wizard all the time but you have to make sure if you modify the database that the dataset gets updated. You can manually create a type dataset, just Project->Add new item->Dataset.
-
Jul 26th, 2015, 03:39 PM
#8
Thread Starter
Frenzied Member
Re: [RESOLVED] Add row to SQL Server table with Primary Key ID field using Identity S
I have created DataSets that way before when I didn't rely on ouside data. I imagine then all one needs to do is create a DataAdapter. What is the easiest way to do that?
-
Jul 26th, 2015, 08:04 PM
#9
Re: [RESOLVED] Add row to SQL Server table with Primary Key ID field using Identity S
Lots of good information Here
Last edited by wes4dbt; Jul 26th, 2015 at 08:11 PM.
-
Jul 27th, 2015, 11:41 AM
#10
Thread Starter
Frenzied Member
Re: [RESOLVED] Add row to SQL Server table with Primary Key ID field using Identity S
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|