Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 17th, 2003, 11:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default Identity field in the Data Row

Hello,

I originally posted this field elsewhere, but I guess it is more of a ADO.NET question. I have a table that looks like this:

ID int
Name varchar(50)
Description varchar(512) NULL

When I add a new record via ADO.NET code, it looks like this:
Code:
dim objRow as DataRow = objTable.NewRow()

objRow("Name") = strName
objRow("Description") = strDescription
objTable.Rows.Add(objRow)
I assumed that when you get the data source from a stored procedure, that it would establish an identity. However, I guess this means that it doesn't? Anyway, if I were to set up the column to be an identity, how can I get the identity field to start where I left off? Do I not have to establish the AutoIncrementSeed but do establish an AutoIncrementStep of 1?

Thanks,

Brian Mains
__________________
Brian
 
Old December 17th, 2003, 02:01 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

When you add the "Identity" property to a column, you typically don't need to make any modifications to have it start off at the right place. If you have 1000 rows (1-1000) the next row added will get identity value of 1001 if you leave all the identity defaults (seed, increment). SQL figures that out for you.

Regarding getting the ID value when you add a row:
I re-read the other thread regarding this topic and I see where the difficulties are. I'm not sure of an immediate solution.

If you have to work with stored procedures, you are going to run into some problems with the ADO interaction. Because you are populating disconnected dataset tables from SPROCs you aren't going to get the "smarts" of the ADO capabilities (which automatically figure out lots of things directly from the table(s)).

If your goal is to be able to add data rows thru a datagrid, you will probably have to modify the datagrid (add row, enter data) then save the record thru a regular SQL call using a SPROC for the insert. Then you rebind the datagrid and your new row will show up as "saved".

I've worked with datagrids, but haven't played with manually adding new rows to the grid control. I don't see why this would be a problem however. You should be able to add a new dataitem to the grid, set the edititemindex to that item's index so that item is in edit mode. Then the update could determine if that's a new item, and make the SQL call accordingly (add new or update).

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old December 17th, 2003, 04:34 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Unfortunately, Stored Procedures are required for me in my applications. With that said, what I was thinking my problem was is that I didn't update automatically to the data grid, but now I'm not so sure. However, I did find other people out there with the same problems I'm having, and have found this solution to the problem:

http://www.dotnetjohn.com/articles/articleid27.aspx

Thanks.





Similar Threads
Thread Thread Starter Forum Replies Last Post
IDENTITY Field ricespn SQL Server 2000 4 November 2nd, 2007 11:40 PM
Getting @@IDENTITY in Row Transform afward SQL Server DTS 2 September 28th, 2005 09:56 AM
Inserting a Value into an SQL Identity Field in VB vbmazza VB Databases Basics 1 April 27th, 2005 02:45 PM
getting identity field chanceeve Classic ASP Databases 2 June 5th, 2004 01:31 AM
SQL Server Identity field won't increment Ron Howerton VB.NET 2002/2003 Basics 8 April 22nd, 2004 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.