473,800 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sqldataadapter

Hello all,

Im inserting 100 rows into the database
i need the Identity column back.

Im not sure how to accomplish this...
Using SqlDataAdapter
Ive Tried samples that i found..but can't get them to work
except for 1 Row...Multiple rows identity column has 0 value
Does anybody know of any links i can read

Thanks
DaveL
Jun 27 '08 #1
2 2326
Small Example of What is Happening
SqlCommandbuild er builds 100 plus Columns and when used does not work
SqlDataAdapter Ad = new SqlDataAdapter( );
Ad.SelectComman d = new SqlCommand("Sel ect top 0 * from MyTable With
(nolock)");
//use Sqlcommand builder
SqlCommandBuild er cmd = new SqlCommandBuild er(Ad);
Ad.SelectComman d.Connection=oC onn;
Ad.InsertComman d = cmd.GetInsertco mmand();

SqlDataSet ds = new SqlDataSet();

oConn.Open()
Ad.Fill(ds,"MyT able")
oConn.Close()
//at this point i have 0 rows/records
//i parse a Text file
//adding rows to this ds.Tables[0] mytable

//.....
//......
// looping through a text file and adding rows
//......
//......
//at this point i have 100 rows in the Table i want to insert them all and
have ds.tables[0] reflect the identity key
// add scope identity to the insert command
Ad.InsertComman d+="; Select Scope_identity( ) as MyIdentity";

oConn.Open()
Ad.Update(ds,"M yTable")
oConn.Close()

ds.AcceptChange s();
// does not work using Sqlcommandbuild er()

console.writeli ne(ds.tables[0]["MyIdentity ") printed values = 0
//if i change the insertcommand to the below than it works
// the below reflects 100 new identities in the data set table[0]
// so im wondering, is there a switch in SqlCommandBuild er or somthing that
i am missing

//if i change the above Insert command to
Ad.InsertComman d.CommandText=" Insert into MyTable (Field1>
values(@Field1) ;Select Scope_identity( ) as MyIdentity";
//
//
Ad.InsertComman d.Parameters.Ad d("@Field1", SqlDbType.Int, 0,"Field1");

"DaveL" <dv*****@sbcglo bal.netwrote in message
news:3A******** *********@newss vr13.news.prodi gy.net...
Hello all,

Im inserting 100 rows into the database
i need the Identity column back.

Im not sure how to accomplish this...
Using SqlDataAdapter
Ive Tried samples that i found..but can't get them to work
except for 1 Row...Multiple rows identity column has 0 value
Does anybody know of any links i can read

Thanks
DaveL


Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2107
by: Steven Blair | last post by:
Hi, Here is a short decsription of my problem. I have written a dll for Database accessing. I have one method which can return a Dataset and another method which takes a Dataset and upates a Database. (Disconnected Datasets). The problem I have is a new SqlAdapter is required before updating the Database: Therefore, to allow the update I have to do the following:
6
4315
by: goodstart123 | last post by:
For example, the following code works fine without SqlConnection. Any Answer to the question? string connectionString = "server=YourServer; uid=sa; pwd=YourPassword; database=ProgASPDotNetBugs"; // get records from the Bugs table string commandString = "Select BugID, Description from Bugs";
3
12713
by: W Akthar | last post by:
I am trying to use SqlDataAdapter to execute a Stored Procedure. The Stored Procedure is as follows CREATE Procedure SP_GetAddressesFromContactID @ID int AS SELECT b.StreetAddress1,
4
396
by: Jerry Higgins | last post by:
I added a SqlDataAdapter to a web form, created a data connection, and generated a dataset. I then connected it to a DataGrid control. When I do this using the SqlServer database on my machine everything works fine. When I do it using a SqlServer database on another machine I get the "Login failed for user sa" error. However, when I right click on the SqlDataAdapter and click "Preview Data" it brings back the data OK. Why would it...
10
2534
by: Victor | last post by:
Hello there, I have a module in VB.NET (ASP.NET) and on top I declare the SqlConnection and the SqlDataAdapter. Like: Module AccessDB Dim sqlCmd As New SqlCommand Dim conAanvraag As New
7
3004
by: Matt Jensen | last post by:
Howdy Fairly simple question I think, I presume the answer is no it can't be reused for 2 *SELECT* statements, but just hoping for clarification. Just asking in the interests of trying to minimise code. i.e. if the SqlDataAdapter uses a connection to the one database for a select statement and I want to do a second select statement on exactly the same database, can I reuse the SqlDataAdapter? I ask because I want to put both 'select'...
4
5300
by: HS1 | last post by:
Hello. I declare a SqlDataAdapter in a FormLoad as below. However, there is error claimed that the SqlDataAdapter is not defined. Could you please tell me what to do ------------------ Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
1
1753
by: archana | last post by:
Hi all I ma having problem in sqldataadapter. In my sql database i have one table containing column name as 'Name and address'. Here 'and' is reserved word which i am using in column name. In sql server at a time of inserting data into the table it is working properly. But when i try to insert data through sqldataadapter in C#, it is
1
8076
by: languy | last post by:
Hi there I'm having a problem when using the SqlDataAdapter. When calling the Update(DataSet, string) method I get the following error message "String or binary data would be truncated". The rows neither have data that exceeds 8000 chars nor contain any LOB fields. Furthermore the data is transferred between two tables that are bitwise identical. -- snip -- System.Data.SqlClient.SqlCommand command =
1
1200
by: kempshall | last post by:
When I use an SqlDataAdapter to fill a DataSet from a database, do I need to explicitly open and close the SqlConnection that I'm using? For example, I have code that looks like this: SqlConnection myConnection = null; try { myConnection = new SqlConnection(ConfigurationSettings.AppSettings); SqlDataAdapter myDA = new SqlDataAdapter( sql, myConnection ); // myConnection.Open();
0
9691
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10276
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10035
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9090
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6813
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.