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. .NET (Core and Framework)
  4. sqlDataAdapter doest not refresh the query

sqlDataAdapter doest not refresh the query

Scheduled Pinned Locked Moved .NET (Core and Framework)
databasehelpquestionlearning
4 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.
  • A Offline
    A Offline
    akosidandan
    wrote on last edited by
    #1

    Hello Experts, Good day/Good Evening Experts I am here again to ask some few questions. :) I would like to ask if why does my sqldataAdapter do not refresh the query it fill my datatable. I am making a borrow transaction for borrowing a book where in a student or ... borrow. The quantity of book will decrease depending on the quantity of book borrowed.My problem is that my sqlDataAdapter to load the table of my bookRecords does not refresh what it need to fill.Confuse :confused:why does it refresh my sql query. Below here is my code:

    'save the borrow transaction
    Public Sub SaveBorrowTransaction(ByVal txtBorrowerID As TextBox, ByVal txtLastName As TextBox, _
    ByVal txtFirstName As TextBox, ByVal txtMI As TextBox, _
    ByVal txtContactNo As TextBox, ByVal cboPosition As ComboBox, _
    ByVal txtYear As TextBox, ByVal txtSection As TextBox, _
    ByVal txtLibrarianLastName As TextBox, ByVal txtLibarianFirstName As TextBox, _
    ByVal txtLibrarianMI As TextBox, ByVal cboNoOfDays As ComboBox, _
    ByVal txtTransactionID As TextBox, _
    ByVal lvItems As ListView, ByVal con As SqlConnection)
    Try
    Dim dt As New DataTable
    Dim ds As New DataSet
    ds.Tables.Add(dt)
    Dim da As New SqlDataAdapter

            con.Open()
            da = New SqlDataAdapter("Select \* from BorrowTransactionTable", con)
            da.Fill(dt)
    
            Dim dt2 As New DataTable
            Dim ds2 As New DataSet
            ds2.Tables.Add(dt2)
            Dim da2 As New SqlDataAdapter
    
            da2 = New SqlDataAdapter("Select \* from transactionitemstable", con)
            da2.Fill(dt2)
    
    
            Dim dt3 As New DataTable
            Dim ds3 As New DataSet
            ds3.Tables.Add(dt3)
            Dim da3 As New SqlDataAdapter
    
            Dim j As Integer = 0
    
    
            While j <> lvItems.Items.Count
    
                'for borrow transaction////////////////////////////////
                Dim newRow As DataRow = dt.NewRow
                With newRow
                    .Item("txtTransactionID") = txtTransactionID.Text
                    .Item("txtBorrowerID") = txtBorrowerID.Text
                    .Item("txtLibrarianLastName") = txtLibrarianLastName.Text
                    .Item(
    
    N 1 Reply Last reply
    0
    • A akosidandan

      Hello Experts, Good day/Good Evening Experts I am here again to ask some few questions. :) I would like to ask if why does my sqldataAdapter do not refresh the query it fill my datatable. I am making a borrow transaction for borrowing a book where in a student or ... borrow. The quantity of book will decrease depending on the quantity of book borrowed.My problem is that my sqlDataAdapter to load the table of my bookRecords does not refresh what it need to fill.Confuse :confused:why does it refresh my sql query. Below here is my code:

      'save the borrow transaction
      Public Sub SaveBorrowTransaction(ByVal txtBorrowerID As TextBox, ByVal txtLastName As TextBox, _
      ByVal txtFirstName As TextBox, ByVal txtMI As TextBox, _
      ByVal txtContactNo As TextBox, ByVal cboPosition As ComboBox, _
      ByVal txtYear As TextBox, ByVal txtSection As TextBox, _
      ByVal txtLibrarianLastName As TextBox, ByVal txtLibarianFirstName As TextBox, _
      ByVal txtLibrarianMI As TextBox, ByVal cboNoOfDays As ComboBox, _
      ByVal txtTransactionID As TextBox, _
      ByVal lvItems As ListView, ByVal con As SqlConnection)
      Try
      Dim dt As New DataTable
      Dim ds As New DataSet
      ds.Tables.Add(dt)
      Dim da As New SqlDataAdapter

              con.Open()
              da = New SqlDataAdapter("Select \* from BorrowTransactionTable", con)
              da.Fill(dt)
      
              Dim dt2 As New DataTable
              Dim ds2 As New DataSet
              ds2.Tables.Add(dt2)
              Dim da2 As New SqlDataAdapter
      
              da2 = New SqlDataAdapter("Select \* from transactionitemstable", con)
              da2.Fill(dt2)
      
      
              Dim dt3 As New DataTable
              Dim ds3 As New DataSet
              ds3.Tables.Add(dt3)
              Dim da3 As New SqlDataAdapter
      
              Dim j As Integer = 0
      
      
              While j <> lvItems.Items.Count
      
                  'for borrow transaction////////////////////////////////
                  Dim newRow As DataRow = dt.NewRow
                  With newRow
                      .Item("txtTransactionID") = txtTransactionID.Text
                      .Item("txtBorrowerID") = txtBorrowerID.Text
                      .Item("txtLibrarianLastName") = txtLibrarianLastName.Text
                      .Item(
      
      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Which of the three DataAdapters are you asking about? What are you expecting to happen? It doesn't even appear you are using the first one. You are creating DataSets then never using them. I would say this could also be handled better with a stored procedure. And lastly, you're using VB X| ;P


      I know the language. I've read a book. - _Madmatt

      A 1 Reply Last reply
      0
      • N Not Active

        Which of the three DataAdapters are you asking about? What are you expecting to happen? It doesn't even appear you are using the first one. You are creating DataSets then never using them. I would say this could also be handled better with a stored procedure. And lastly, you're using VB X| ;P


        I know the language. I've read a book. - _Madmatt

        A Offline
        A Offline
        akosidandan
        wrote on last edited by
        #3

        Hello, Sorry bout not giving good info for my question, the problem came from my 3rd dataAdapter at this part:

        'update changes to quantity of book catalogue records when borrowing///////////////////
        da3 = New SqlDataAdapter("Select * from BookCatalogueTable where txtAccessionNo='" lvItems.Items(j).SubItems(0).Text & "'", con)
        da3.Fill(dt3)
        dt3.Rows(0).BeginEdit()
        dt3.Rows(0).Item("intQuantity") = Val(dt3.Rows(0).Item("intQuantity")) - 1
        dt3.Rows(0).EndEdit()
        Dim cb3 As New SqlCommandBuilder(da3)
        da3.Update(dt3)

        My da3 suppose to load again the new query while its on a loop block so that I can Subtract those quantity value,but my da3 doesn't refresh the query that will load new records. For example my da3 select query at first is "Select * from BookCatalogueTable where txtAccessionNo='1'". After I update the table the new da3 select query for example become "Select * from BookCatalogueTable where txtAccessionNo='2'".My da3 does not execute the next query instead it still using the first query. :) If my question is not yet clear I can still clarify to the best I can. I'm really confuse why my da3 doesn't load the new query. All comments and suggestion are soo much appreciated. Thanks, Dan

        N 1 Reply Last reply
        0
        • A akosidandan

          Hello, Sorry bout not giving good info for my question, the problem came from my 3rd dataAdapter at this part:

          'update changes to quantity of book catalogue records when borrowing///////////////////
          da3 = New SqlDataAdapter("Select * from BookCatalogueTable where txtAccessionNo='" lvItems.Items(j).SubItems(0).Text & "'", con)
          da3.Fill(dt3)
          dt3.Rows(0).BeginEdit()
          dt3.Rows(0).Item("intQuantity") = Val(dt3.Rows(0).Item("intQuantity")) - 1
          dt3.Rows(0).EndEdit()
          Dim cb3 As New SqlCommandBuilder(da3)
          da3.Update(dt3)

          My da3 suppose to load again the new query while its on a loop block so that I can Subtract those quantity value,but my da3 doesn't refresh the query that will load new records. For example my da3 select query at first is "Select * from BookCatalogueTable where txtAccessionNo='1'". After I update the table the new da3 select query for example become "Select * from BookCatalogueTable where txtAccessionNo='2'".My da3 does not execute the next query instead it still using the first query. :) If my question is not yet clear I can still clarify to the best I can. I'm really confuse why my da3 doesn't load the new query. All comments and suggestion are soo much appreciated. Thanks, Dan

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          As I said, this is better handled with other methods, i.e. not using a DataAdapter for everything. You creating far too much overhead and I'm sure your code doesn't perform well. Use a stored proc to handle this, or use SqlCommands directly.


          I know the language. I've read a book. - _Madmatt

          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