|
-
Aug 26th, 2012, 09:59 AM
#1
Thread Starter
New Member
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.
-
Aug 26th, 2012, 10:18 AM
#2
Thread Starter
New Member
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.
-
Aug 26th, 2012, 10:25 AM
#3
Re: List + Populate + function + database + windows Forms
vb.net Code:
Dim cmd As New OleDbCommand
Dim db As New dbconnection 'and this is .... ?
cmd.Connection = db.connection 'this has no value so there's no connection and therefore no data
-
Aug 26th, 2012, 10:34 AM
#4
Thread Starter
New Member
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.
-
Aug 26th, 2012, 11:42 AM
#5
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.
-
Aug 26th, 2012, 12:12 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|