PoeticAudio
asked on
Writing data to a database from a datagrid
How would I write data back into a database using a DataGrid on a non-web project?
Thanks,
Thanks,
In my second approach,
To initiate your objects, use:
myConn = new OleDbConnection("Provider= Microsoft. Jet.OLEDB. 4.0;Data Source=C:\\myFolder\\myDat aBase.mdb" );
cmd = new OleDbCommand("", myConn);
This example uses Microsoft Acess database.
If you have difficulty of making it work with other type of database, let me know.
stone.
To initiate your objects, use:
myConn = new OleDbConnection("Provider=
cmd = new OleDbCommand("", myConn);
This example uses Microsoft Acess database.
If you have difficulty of making it work with other type of database, let me know.
stone.
ASKER
I'm getting an exception:
I'm trying to use
dataAdapter1.Update(dataSe t1, "tblClient");
but i'm getting this
"Update requires a valid UpdateCommand when passed DataRow collection with modified rows."
Sorry, i'm totally new to this
I'm trying to use
dataAdapter1.Update(dataSe
but i'm getting this
"Update requires a valid UpdateCommand when passed DataRow collection with modified rows."
Sorry, i'm totally new to this
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Solution #1:
I presume that you are using an OleDbDataApapter and a DataSet object between your database and datagird.
Then use Update method to save your datagrid data back to database:
oleDbDataAdapter1.Update(m
Solution #2: use embedded SQL statement.
Create an OleDbConnection to open a connection to your database, and an OleDbCommand object to execute SQL statement.
OleDbConnection myConn;
OleDbCommand cmd;
myConn.Open();
cmd.CommandText = "UPDATE myTableName SET theColumnName= @myValue WHERE nID = @myID";
cmd.Parameters.Add("@myVal
cmd.Parameters.Add("@myID"
cmd.ExecuteNonQuery();
myConn.Close();