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. Database & SysAdmin
  3. Database
  4. datatable only working occasionally

datatable only working occasionally

Scheduled Pinned Locked Moved Database
databasehelpcsharpdata-structures
3 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.
  • L Offline
    L Offline
    lxhan
    wrote on last edited by
    #1

    I have a VB.Net windows app that retrieves data from 3 different tables. The SQL command uses a 3 table join. The results from the query is filled into a datatable and later populated into a combobox. The SQL uses the values from a date field inside a text field, for example, 01-15-2005. So, each time I submit the subroutine it executes the SQL command and VB.Net code to retrieve the required data. The date field changes according to the user’s needs. There’s no consistency when the error pops up. The error message I’m getting when it executes, da.Fill(dataTable), “There’s no row at position 0”,. The information I’m on the stack track is as follow: Calling SQLDisconnect --- OleDB UnInitialize not called!!! Connection Object destroyed If I copy the sql into a sql query tool it does retrieve the required data according to the date field. Here’s a sample of the subroutine: cmdQueryINVOICE = _ "SELECT PAYITEM.TRANSACT_NUMBER, " _ & "PAYITEM.ACCOUNT_NUMBER, " _ & "PAYITEM.PAY_DATE, " _ & "LSEINVH.INVOICE_NUMBER " _ & "FROM LSEINVH, PAYITEM, TRANSHDR " _ & "WHERE " _ & " LSEINVH.INVOICE_NUMBER > '" & 75000 _ & "' AND LSEINVH.STATUS <> '" & sStatus _ & "' AND LSEINVH.INVOICE_NUMBER = TRANSHDR.INVOICE_NUMBER " _ & " AND PAYITEM.PAY_DATE > '" & InvoiceDates.StartDate _ & "' AND PAYITEM.PAY_DATE < '" & InvoiceDates.EndDate _ & "' AND PAYITEM.COMPANY = '" & sCompany _ & "' AND PAYITEM.TRANSACT_NUMBER = TRANSHDR.TRANS_NUMBER order by PAYITEM.PAY_DATE desc " Dim sqlQuery As OleDbCommand = connDf.CreateCommand Dim dtInvDate As New DataTable() Dim iInvCnt, x As Integer Dim sUnitQuery As String Dim daInv As New OleDbDataAdapter() Try daInv = New OleDbDataAdapter(cmdQueryINVOICE, connDf) daInv.Fill(dtInvDate) Dim LoopRow As Data.DataRow Dim test As String = dtInvDate.Rows.Item(0).ToString For Each LoopRow In dtInvDate.Rows cboInvoice.Items.Add(LoopRow.Item("INVOICE_NUMBER").ToString + " " + LoopRow.Item("PAY_DATE")) Next Catch e As Exception Dim errMsg As String = e.Message Finally connDf.Close() End Try Thanks, for any help!

    C 1 Reply Last reply
    0
    • L lxhan

      I have a VB.Net windows app that retrieves data from 3 different tables. The SQL command uses a 3 table join. The results from the query is filled into a datatable and later populated into a combobox. The SQL uses the values from a date field inside a text field, for example, 01-15-2005. So, each time I submit the subroutine it executes the SQL command and VB.Net code to retrieve the required data. The date field changes according to the user’s needs. There’s no consistency when the error pops up. The error message I’m getting when it executes, da.Fill(dataTable), “There’s no row at position 0”,. The information I’m on the stack track is as follow: Calling SQLDisconnect --- OleDB UnInitialize not called!!! Connection Object destroyed If I copy the sql into a sql query tool it does retrieve the required data according to the date field. Here’s a sample of the subroutine: cmdQueryINVOICE = _ "SELECT PAYITEM.TRANSACT_NUMBER, " _ & "PAYITEM.ACCOUNT_NUMBER, " _ & "PAYITEM.PAY_DATE, " _ & "LSEINVH.INVOICE_NUMBER " _ & "FROM LSEINVH, PAYITEM, TRANSHDR " _ & "WHERE " _ & " LSEINVH.INVOICE_NUMBER > '" & 75000 _ & "' AND LSEINVH.STATUS <> '" & sStatus _ & "' AND LSEINVH.INVOICE_NUMBER = TRANSHDR.INVOICE_NUMBER " _ & " AND PAYITEM.PAY_DATE > '" & InvoiceDates.StartDate _ & "' AND PAYITEM.PAY_DATE < '" & InvoiceDates.EndDate _ & "' AND PAYITEM.COMPANY = '" & sCompany _ & "' AND PAYITEM.TRANSACT_NUMBER = TRANSHDR.TRANS_NUMBER order by PAYITEM.PAY_DATE desc " Dim sqlQuery As OleDbCommand = connDf.CreateCommand Dim dtInvDate As New DataTable() Dim iInvCnt, x As Integer Dim sUnitQuery As String Dim daInv As New OleDbDataAdapter() Try daInv = New OleDbDataAdapter(cmdQueryINVOICE, connDf) daInv.Fill(dtInvDate) Dim LoopRow As Data.DataRow Dim test As String = dtInvDate.Rows.Item(0).ToString For Each LoopRow In dtInvDate.Rows cboInvoice.Items.Add(LoopRow.Item("INVOICE_NUMBER").ToString + " " + LoopRow.Item("PAY_DATE")) Next Catch e As Exception Dim errMsg As String = e.Message Finally connDf.Close() End Try Thanks, for any help!

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      You should tell us what the database is. There may be subtle differences between them. Your code is most insecure. It is the potential subject of a SQL Injection Attack. You should read this article about how to prevent them: http://www.codeproject.com/useritems/SqlInjectionAttacks.asp[^] Is your connection open before calling the Fill on the data adapter? If the connection is closed when you call Fill then the data adapter will open the connection, perform the action and then close the connection again. So the Close statement in the finally block is redundant.


      Do you want to know more? WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums

      L 1 Reply Last reply
      0
      • C Colin Angus Mackay

        You should tell us what the database is. There may be subtle differences between them. Your code is most insecure. It is the potential subject of a SQL Injection Attack. You should read this article about how to prevent them: http://www.codeproject.com/useritems/SqlInjectionAttacks.asp[^] Is your connection open before calling the Fill on the data adapter? If the connection is closed when you call Fill then the data adapter will open the connection, perform the action and then close the connection again. So the Close statement in the finally block is redundant.


        Do you want to know more? WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums

        L Offline
        L Offline
        lxhan
        wrote on last edited by
        #3

        Thanks for your suggestion. I decided to retrieve the entire results from the query and fill the dataset, so I don't experience the problem. Thanks again for the recommendation of sql injection I'll look into to it, but this is a windows application I thought sql was only for web application?

        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