dataset.acceptchange method.. [modified]
-
i am usind dataadapter and dataset objects to bind some data from the database in the textbox control. the code i m using is as follows:
textbox1.databindigs.add("text",dataset.tables(0),"Name")
This code is able to retrieve the field 'Name' from the database and puts it in this textbox. Now i want that if some change is made in this textbox,then that should be updated to the database table as well. for this purpose i m using dataset.acceptchange method. But this is not giving result. please guide me in this.. thanks.. -- modified at 14:42 Monday 19th March, 2007 -
i am usind dataadapter and dataset objects to bind some data from the database in the textbox control. the code i m using is as follows:
textbox1.databindigs.add("text",dataset.tables(0),"Name")
This code is able to retrieve the field 'Name' from the database and puts it in this textbox. Now i want that if some change is made in this textbox,then that should be updated to the database table as well. for this purpose i m using dataset.acceptchange method. But this is not giving result. please guide me in this.. thanks.. -- modified at 14:42 Monday 19th March, 2007manni_n wrote:
the code i m using is as follows: textbox1.databindigs.add("text",dataset.tables(0),"Name")
This code just sets up a single databinding and it's not even the code you used. Copy and Paste the REAL code you're using. Do not retype the code yourself! What's the code that's filling the DataSet your binding to? What does the code look like where you're writing the DataSet back to the database?
manni_n wrote:
for this purpose i m using dataset.acceptchange method
Do you know what AcceptChanges does?
Dave Kreskowiak Microsoft MVP - Visual Basic
-
manni_n wrote:
the code i m using is as follows: textbox1.databindigs.add("text",dataset.tables(0),"Name")
This code just sets up a single databinding and it's not even the code you used. Copy and Paste the REAL code you're using. Do not retype the code yourself! What's the code that's filling the DataSet your binding to? What does the code look like where you're writing the DataSet back to the database?
manni_n wrote:
for this purpose i m using dataset.acceptchange method
Do you know what AcceptChanges does?
Dave Kreskowiak Microsoft MVP - Visual Basic
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try Dim da As New OleDbDataAdapter("select * from dbo_info where IDNo='" & Label2.Text & "' ", "provider=microsoft.jet.oledb.4.0;data source=e:\new folder\testIP.mdb;") Dim ds As New DataSet da.Fill(ds) Label2.DataBindings.Add("text", ds.Tables(0), "IDNo") Label43.DataBindings.Add("text", ds.Tables(0), "Name") Label42.DataBindings.Add("text", ds.Tables(0), "ParName")
i am using this code to bind the text box ... imean i am able to retrieve the data in the database now i want if something is changed in that textbox then that change should be updated in same data base.. i want to use dataset acceptchange method .... i dont have that much knowledge in this coding... please tell me the way to do this.... method other than dataset accept is also welcome....just i want to solve my purpose thanks.... -
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try Dim da As New OleDbDataAdapter("select * from dbo_info where IDNo='" & Label2.Text & "' ", "provider=microsoft.jet.oledb.4.0;data source=e:\new folder\testIP.mdb;") Dim ds As New DataSet da.Fill(ds) Label2.DataBindings.Add("text", ds.Tables(0), "IDNo") Label43.DataBindings.Add("text", ds.Tables(0), "Name") Label42.DataBindings.Add("text", ds.Tables(0), "ParName")
i am using this code to bind the text box ... imean i am able to retrieve the data in the database now i want if something is changed in that textbox then that change should be updated in same data base.. i want to use dataset acceptchange method .... i dont have that much knowledge in this coding... please tell me the way to do this.... method other than dataset accept is also welcome....just i want to solve my purpose thanks....You don't have any code to write the dataset changes back to the database. You can use the same dataadapter object that you use to populate the dataset, but you have to give it the SqlCommands to make the Insert, Update, and Delete changes to the actual database. You can either do this by hand or, if you're old using a single table in your SELECT query, you can use the OleDbCOmmandBuilder class to make the other thre queries for you. You could modify your code like this:
Dim da As New OleDbDataAdapter("select * from dbo_info where IDNo='" & Label2.Text & "' ", _
"provider=microsoft.jet.oledb.4.0;data source=e:\new folder\testIP.mdb;")
Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(myDataAdapter)Dim ds As New DataSet
da.Fill(ds)You'd probably also want to make the DataSet and DataAdapter class-scope so you can use it from something like a "Submit" button. When you want to save the changes back to the database:
da.Update(ds)
Dave Kreskowiak Microsoft MVP - Visual Basic
-
You don't have any code to write the dataset changes back to the database. You can use the same dataadapter object that you use to populate the dataset, but you have to give it the SqlCommands to make the Insert, Update, and Delete changes to the actual database. You can either do this by hand or, if you're old using a single table in your SELECT query, you can use the OleDbCOmmandBuilder class to make the other thre queries for you. You could modify your code like this:
Dim da As New OleDbDataAdapter("select * from dbo_info where IDNo='" & Label2.Text & "' ", _
"provider=microsoft.jet.oledb.4.0;data source=e:\new folder\testIP.mdb;")
Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(myDataAdapter)Dim ds As New DataSet
da.Fill(ds)You'd probably also want to make the DataSet and DataAdapter class-scope so you can use it from something like a "Submit" button. When you want to save the changes back to the database:
da.Update(ds)
Dave Kreskowiak Microsoft MVP - Visual Basic
-
you have initialized cb but havnt used anywhere.... whats the use of cb in this coding....?