I haven't dealt much with databases before, so this is probably an easy question, but here goes:
I am trying to insert a new row into a table in a database. The table has earlier been loaded into a DataSet (objDataSet), and the Connection has also been created (objCon) without problems.
I've tried to do this in two different ways but the first one doesnt seem to work properly and the second one causes an error:
1)
string strSQL = "INSERT INTO........";
OleDbDataAdapter objAda = new OleDbDataAdapter();
objAda.InsertCommand = new OleDbCommand(strSQL, objCon);
So how do i make this insertcommand execute? I have tried using
objAda.Update(objDataSet, "TableName");
this will run fine, but nothing happens to the table in the database.
2)
DataRow row = objDataSet.Tables["TableName"].NewRow();
<assign data to new row>
objDataSet.Tables["TableName"].Rows.Add(row);
OleDbDataAdapter objAda = new OleDbDataAdapter();
objAda.UpdateCommand = new OleDbCommand("UPDATE TableName", objCon);
objAda.Update(objDataSet, "TableName");
this will cause an error saying "Update requires a valid InsertCommand when passed DataRow collection with new rows." So what should this InsertCommand look like?
I am trying to insert a new row into a table in a database. The table has earlier been loaded into a DataSet (objDataSet), and the Connection has also been created (objCon) without problems.
I've tried to do this in two different ways but the first one doesnt seem to work properly and the second one causes an error:
1)
string strSQL = "INSERT INTO........";
OleDbDataAdapter objAda = new OleDbDataAdapter();
objAda.InsertCommand = new OleDbCommand(strSQL, objCon);
So how do i make this insertcommand execute? I have tried using
objAda.Update(objDataSet, "TableName");
this will run fine, but nothing happens to the table in the database.
2)
DataRow row = objDataSet.Tables["TableName"].NewRow();
<assign data to new row>
objDataSet.Tables["TableName"].Rows.Add(row);
OleDbDataAdapter objAda = new OleDbDataAdapter();
objAda.UpdateCommand = new OleDbCommand("UPDATE TableName", objCon);
objAda.Update(objDataSet, "TableName");
this will cause an error saying "Update requires a valid InsertCommand when passed DataRow collection with new rows." So what should this InsertCommand look like?