FMabey
asked on
Updating a database from a datagrid
Hi all,
I am using VB.NET (VS 2003), with SQL Server 2000.
I have a datagrid which is populated through a dataset with information from a SQL Server table. The user is to be able to add rows to the existing data and also change some of the data that has already been pulled out of SQL Server.
My question is, what is the best way to go about updating the database with all changes? When should the update occur? What code should I use?
Any comments would be great.
I am using VB.NET (VS 2003), with SQL Server 2000.
I have a datagrid which is populated through a dataset with information from a SQL Server table. The user is to be able to add rows to the existing data and also change some of the data that has already been pulled out of SQL Server.
My question is, what is the best way to go about updating the database with all changes? When should the update occur? What code should I use?
Any comments would be great.
ASKER
I have found this way of updating the database with any changes:
DataAdapter.Update(DataSet .GetChange s())
Can anyone see any problems with this?
DataAdapter.Update(DataSet
Can anyone see any problems with this?
see this link
http://authors.aspalliance.com/aspxtreme/sys/Data/common/DataAdapterClassUpdate.aspx
here
public DataSet updateData ( DataSet myDataSet,
string connString, string query ) {
OleDbConnection myConn = new OleDbConnection ( connString );
OleDbDataAdapter adapter = new OleDbDataAdapter ( );
adapter.SelectCommand = new OleDbCommand ( query, myConn );
OleDbCommandBuilder custCB = new OleDbCommandBuilder ( adapter );
DataSet myDataSet = new DataSet ( );
us used to update the database.
u need OleDbCommandBuilder to update the dataset
http://authors.aspalliance.com/aspxtreme/sys/Data/common/DataAdapterClassUpdate.aspx
here
public DataSet updateData ( DataSet myDataSet,
string connString, string query ) {
OleDbConnection myConn = new OleDbConnection ( connString );
OleDbDataAdapter adapter = new OleDbDataAdapter ( );
adapter.SelectCommand = new OleDbCommand ( query, myConn );
OleDbCommandBuilder custCB = new OleDbCommandBuilder ( adapter );
DataSet myDataSet = new DataSet ( );
us used to update the database.
u need OleDbCommandBuilder to update the dataset
ASKER
Why can I not use the code I have posted? It seems to work fine for what I want to do....
k it means u got some full fleash code to fullfill ur requirement.
If it is working fine then carry on.
Good luck
If it is working fine then carry on.
Good luck
ASKER
What I wondered was if this is the correct way to go about things or is it (unsafe?!) not a great method.
How do people usually update their data in these situations?
How do people usually update their data in these situations?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
1) fille the datagrid with the specified table.
2) create some text fields and a button to add the field's values to the dataTable , and then also insert to the database. use this :
datatableCust.rows.add()
3) use an Update column in the datagrid to update the existing details.