Results 1 to 6 of 6

Thread: List + Populate + function + database + windows Forms

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2012
    Posts
    6

    List + Populate + function + database + windows Forms

    Code:
    Public Function popdrawschedules()
    	        Dim cmd As New OleDbCommand
    	        Dim db As New dbconnection
    	        cmd.Connection = db.connection
    	        'Dim todate As Date = Now.ToShortDateString
    	        cmd.CommandText = "select drawcode,typecode,drawtime from drawschedules where drawdate >= to_date(to_char(current_date),'mm-dd-yy')"
    	        'cmd.Parameters.AddWithValue("", todate)
    	 
    	        Dim i As Integer = 0
    	        Dim list As New List(Of String)
    	        Dim list2 As New List(Of String)
    	        Dim list3 As New List(Of String)
    	 
    	        Dim dr As OleDbDataReader
    	        Dim found As Boolean = False
    	        dr = cmd.ExecuteReader
    	        While dr.Read
    	            found = True
    	            list(i) = dr("drawcode")
    	            list2(i) = dr("typecode")
    	            list3(i) = dr("drawtime")
    	            i = i + 1
    	            'ReDim Preserve arr(i)
    	       End While
    	 
    	        Dim cummList As New List(Of String)
    	        For k As Integer = 0 To list.Count - 1
    	            cummList(k) = list(k) & " " & list2(k) & " " & list3(k)
    	            k = k + 1
    	        Next
    	 
    	        cmd.Dispose()
    	        dr.Close()
    	        Return cummList
    	    End Function
    	 
    	Private Sub CheckDraw_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    	 
    	Dim ds As New drawschedules
    	 
    	        Dim found As Boolean = ds.checkdrawschedules
    	        If found = True Then
    	            Panel1.Visible = True
    	            Me.lstTypeName.Items.Clear()
    	            Me.lstTypeName.Items.AddRange(ds.popdrawschedules())
    	        Else
    	            Me.lblMessage.Visible = True
    	        End If
    	End Sub
    This code is supposed to populate a list with values from a table but the list keeps on being empty.
    Ps: I'm new to vb.net so please help me figure this out pronto.

  2. #2

    Thread Starter
    New Member
    Join Date
    Aug 2012
    Posts
    6

    Re: List + Populate + function + database + windows Forms

    the 'drawschedules' is a table in an oracle database and the 'typecode drawcode and drawtime' are columns in that table. The code is supposed to take each value from each column and store it in three different list(list,list2,list3) representing the three different columns, at the it should join all three list into one list and return the joined list(cummList) after which it should populate a list box with the returned list.

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: List + Populate + function + database + windows Forms

    vb.net Code:
    1. Dim cmd As New OleDbCommand
    2.             Dim db As New dbconnection 'and this is .... ?
    3.             cmd.Connection = db.connection 'this has no value so there's no connection and therefore no data

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2012
    Posts
    6

    Re: List + Populate + function + database + windows Forms

    Oh there's definitely a connection i've already tested it and it works with update, insert and delete but the function doesn't return anything.

  5. #5
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: List + Populate + function + database + windows Forms

    Right. Well, there you go then. Complete mystery. Obviously the gods of programming are messing with you mind and there's nothing I can do to stop them. Well, better luck next time.

    Obviously not worth you stepping through the code to see if you might just be mistaken? Looking up what happens when you Dim a variable? No, of course not. You've got it all sussed. Right, well I guess my work is done. Happy programming.

  6. #6
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: List + Populate + function + database + windows Forms

    Someone's having a bad day (again).

    I see you are calling the function popdrawschedules from your form's Load event handler. I'm wondering if you're using a 64 bit OS since exceptions occuring in the Load event handler are unfortunately swallowed while debugging under a 64bit operating system.

    This line
    Code:
    cummList(k) = list(k) & " " & list2(k) & " " & list3(k)
    will throw an exception as you can not index an empty list (you declared it as New in the previous line).

    Try
    Code:
    cummList.add(list(k) & " " & list2(k) & " " & list3(k))
    instead.

    And while you're at it, add an As clause to your function's declaration
    Code:
     Public Function popdrawschedules() As List(Of String)
    Last edited by Inferrd; Aug 26th, 2012 at 12:26 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width