A
Alex
I would like to insert a row into a table using a command builder.
table: col 1: string, col 2: uniqueidentifier. (I set the newID() as the
default value for uniqueid).
Do I need then to generate the ID before inserting it, or does the update
function take care?
Here is my code to insert a row into a table, something seems to be wrong:
SqlConnection myConn = new SqlConnection ( "server=xyz; Integrated
Security=SSPI; Persist Security Info=False; database=myDB" );
myConn.Open();
SqlDataAdapter myAdapter = new SqlDataAdapter ( "select * from table",
myConn );
SqlCommandBuilder custCB = new SqlCommandBuilder(myAdapter);
DataSet dataset = new DataSet();
myAdapter.Fill(dataset, "table");
DataRow newrow = sponsors.Tables["table"].NewRow();
newrow["somestring"] = "xyz";
dataset.Tables["table"].Rows.Add(newrow);
myAdapter.Update(dataset,"table");
myConn.Close();
myConn.Dispose();
table: col 1: string, col 2: uniqueidentifier. (I set the newID() as the
default value for uniqueid).
Do I need then to generate the ID before inserting it, or does the update
function take care?
Here is my code to insert a row into a table, something seems to be wrong:
SqlConnection myConn = new SqlConnection ( "server=xyz; Integrated
Security=SSPI; Persist Security Info=False; database=myDB" );
myConn.Open();
SqlDataAdapter myAdapter = new SqlDataAdapter ( "select * from table",
myConn );
SqlCommandBuilder custCB = new SqlCommandBuilder(myAdapter);
DataSet dataset = new DataSet();
myAdapter.Fill(dataset, "table");
DataRow newrow = sponsors.Tables["table"].NewRow();
newrow["somestring"] = "xyz";
dataset.Tables["table"].Rows.Add(newrow);
myAdapter.Update(dataset,"table");
myConn.Close();
myConn.Dispose();