Link to home
Start Free TrialLog in
Avatar of FMabey
FMabeyFlag for United Kingdom of Great Britain and Northern Ireland

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.
Avatar of Ajay Sharma
Ajay Sharma
Flag of India image

Do it in three way

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.
Avatar of FMabey

ASKER

I have found this way of updating the database with any changes:
DataAdapter.Update(DataSet.GetChanges())

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
Avatar of FMabey

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
Avatar of FMabey

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?
ASKER CERTIFIED SOLUTION
Avatar of Ajay Sharma
Ajay Sharma
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial