Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. dataset.acceptchange method.. [modified]

dataset.acceptchange method.. [modified]

Scheduled Pinned Locked Moved Visual Basic
databasetutorial
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    manni_n
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • M manni_n

      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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • D Dave Kreskowiak

        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

        M Offline
        M Offline
        manni_n
        wrote on last edited by
        #3

        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....

        D 1 Reply Last reply
        0
        • M manni_n

          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....

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          M 1 Reply Last reply
          0
          • D Dave Kreskowiak

            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

            M Offline
            M Offline
            manni_n
            wrote on last edited by
            #5

            you have initialized cb but havnt used anywhere.... whats the use of cb in this coding....?

            D 1 Reply Last reply
            0
            • M manni_n

              you have initialized cb but havnt used anywhere.... whats the use of cb in this coding....?

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              You don't do anything with it. Read up on the OleDbCommandBuilder class here[^].

              Dave Kreskowiak Microsoft MVP - Visual Basic

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups