473,498 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ?
}

-----------------------------------------------
Thanks for your any comments

Albert Guo
Jiangsu Police Institute ,China PRC
Nov 16 '05 #1
1 1318
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/de...singwizard.asp

Good luck :)
Branimir

--
Branimir Giurov
MCSD.NET, MCDBA
"¹ùÑÇ·æ" <gr*************@yahoo.com> wrote in message
news:eH**************@TK2MSFTNGP09.phx.gbl...
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 ?
}

-----------------------------------------------
Thanks for your any comments

Albert Guo
Jiangsu Police Institute ,China PRC

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
10539
by: Mark | last post by:
A beginner in this area, I have been able to read a record from a MySQL database and populate an HTML form (wow!). Now, my goal is to allow the user to edit the contents of the form and then...
16
16972
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
6
2402
by: Jeff Kowalczyk | last post by:
I need to adapt this an update statement to a general form that will iterate over multiple orderids for a given customerinvoiceid. My first concern is a form that will work for a given orderid,...
9
4331
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
1
2980
by: Wing | last post by:
Hi all, I have created 2 tables in sql database and join these 2 tables before assign the result to the dataset, and display the result in datagrid. Everything is fine up to this point. The...
1
2831
by: Neo | last post by:
I konw that one can make use of the default UpdateCommand in the DataAdapter to save changes back into the underlying data source. But i was wondering how one could build a custom update command &...
5
2586
by: Stephen Plotnick | last post by:
I'm very new to VB.NET 2003 Here is what I have accomplished: MainSelectForm - Selects an item In a public class I pass a DataViewRow to ItemInformation1 Form ItemInformation2 Form
5
5329
by: wpellett | last post by:
I can not get the SQL compiler to rewrite my SQL UPDATE statement to include columns being SET in a Stored Procedure being called from a BEFORE UPDATE trigger. Example: create table...
2
3081
by: Miro | last post by:
I will ask the question first then fumble thru trying to explain myself so i dont waste too much of your time. Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an index - i...
5
2138
by: explode | last post by:
I made a procedure Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String) that creates a new oledbDataAdapter with insert update select and delete commads. I also added that commands can...
0
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7203
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4908
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4588
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1417
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
290
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.