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