how to update data from datagrid and store back in datasorce

karthikyon

New member
Joined
Jan 12, 2006
Messages
2
Programming Experience
Beginner
Hi the following code displays the data from datasource in a datagrid....


Dim oData As New Sanega.Hospital.DataAccess.DataAccess
Dim strsql As String
strsql = " select ID,NAME,LINE_1,LINE_2,STREET,CITY,STATE,COUNTRY,ZIP,PHONE_1,PHONE_2,FAX_1,FAX_2,EMAIL,Discontinued from ENTITY_MASTER,ADDRESS_MASTER,CONTACT_MASTER,DISCONTINUED"
Dim myDataSet As DataSet
myDataSet = oData.ReturnDS(strsql, "ENTITY_MASTER")
DataGrid1.DataSource = myDataSet

I hwanted to allow editing and updating the data in datagrid and store the updated data back to the datasorce.................

Please help by sending some sample code examples.....

karthikyon :confused:
 
The DataGrid has nothing to do with committing changes back to the database. You're using a class named Sanega.Hospital.DataAccess.DataAccess to retrieve your data. It should have a corrsponding method to commit any changes back to the database. The DataAdapter classes have a Fill method to retrieve data and an Update method to send changes back to the database. I suggest that you read the help/MSDN topics for the class and those methods to get an understanding of how they work. There are links in my signature to tutorials that contain sections on ADO.NET.
 
Thank U

jmcilhinney said:
The DataGrid has nothing to do with committing changes back to the database. You're using a class named Sanega.Hospital.DataAccess.DataAccess to retrieve your data. It should have a corrsponding method to commit any changes back to the database. The DataAdapter classes have a Fill method to retrieve data and an Update method to send changes back to the database. I suggest that you read the help/MSDN topics for the class and those methods to get an understanding of how they work. There are links in my signature to tutorials that contain sections on ADO.NET.


THANK U FOR UR KIND HELP...........

KARTHIKYON
 
You can execute the SqlCommand to insert/update/delete records like this -


Dim myCommand As New SqlClient.SqlCommand
Dim myTrans As SqlClient.SqlTransaction
myTrans = SqlConnection1.BeginTransaction()
myCommand.Connection = SqlConnection1
myCommand.Transaction = myTrans
Try
str = "<QUERY>"
myCommand.CommandText = str
myCommand.ExecuteNonQuery()
myTrans.Save("Temp")
myTrans.Commit()
Catch ex As Exception
MsgBox("Error")
Finally
End Try

If you can use the DataAdapters then you can save changes to database directly by using

myDataAdapter.Update(myDataSet)
 
Back
Top