How to update data in SQL-SERVER

¹

¹ùÑÇ·æ

I want to write a program to manipulate data in SQL-SERVER.
in my app form , i want to use a datagrid to display & update datas, so i
fill some codes as follows:

private void Run_Click(object sender, System.EventArgs e)
{
if(sqlCon.State == ConnectionState.Open)
sqlCon.Close();
sqlCon.ConnectionString = conLogoin1.ConnectionString;

sqlCon.Open();

SqlDataAdapter sqlDA = new SqlDataAdapter("SELECT * FROM " +
conLogoin1.LTable, sqlCon);
DataSet ds = new DataSet(conLogoin1.LTable);
sqlDA.Fill(ds, conLogoin1.LTable);
dataGrid1.DataSource = ds.Tables[conLogoin1.LTable].DefaultView;

}

but how can i update the data modified in datagrid ?

just like :

private void Update_Click(object sender, System.EventArgs e)
{
//some code to update the data modified in the datagrid
//how can I ?
}
 
B

Branimir Giurov

Hi there,

the best way to do that , is to use the build-in the SqlDataAdapter object
InsertCommand, UpdateCommand and DeleteCommand properties, through which the
adapter actually exposes another instances of the SqlCommand class.
If you're using the build-in SqlDataAdapter wizard, you can automatically
generate either stored procedures or SQL statements for all of the
operations with or without optimistic concurency ability (which gives you a
way to detect data changes between the time you've selected the data and the
moment when you're trying to update it).
For more information, check out
http://msdn.microsoft.com/library/d...html/vbtskcreatingdataadaptersusingwizard.asp

Good luck :)
Branimir
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top