|
-
Nov 10th, 2006, 03:19 PM
#1
Thread Starter
New Member
Casting Error?? [RESOLVED]
What i am trying to do is load a combo box on a form frmStudents. The way i am going about doing it is my frmstudent on load event has this code
VB Code:
Private stu As Student
Private Sub frmDisplayStudent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
stu = New Student
cboStudents.DataSource = stu.GetStudents
cboStudents.DisplayMember = "FIRSTNAME"
End Sub
stu calls to class Student which as a function of GetStudents which does this
VB Code:
Public Function GetStudents() As ArrayList
conn = New SqlConnection(connstring)
Dim sql As String = "SELECT * FROM Student"
comm = New SqlCommand(sql, conn)
Dim stu As New Student
Dim students As New ArrayList
conn.Open()
Dim reader As SqlDataReader = comm.ExecuteReader(CommandBehavior.CloseConnection)
Do While reader.Read
stu = New Student(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), _
reader.GetString(4), reader.GetString(5), reader.GetString(6), reader.GetString(7))
students.Add(stu)
Loop
reader.Close()
conn.Close()
Return students
End Function
When i try to load the form it says i have a casting error? specifically "Specified cast is not valid."
Last edited by SaitStudent; Nov 12th, 2006 at 11:43 PM.
Reason: Resolved
-
Nov 10th, 2006, 03:40 PM
#2
Thread Starter
New Member
Re: Casting Error??
o and i am using sqlServer 2005 and visual studio 2005, code is in VB
-
Nov 10th, 2006, 07:05 PM
#3
Hyperactive Member
Re: Casting Error??
 Originally Posted by SaitStudent
o and i am using sqlServer 2005 and visual studio 2005, code is in VB
Hmm...this is just a guess since I don't use VB.NET but maybe you're using .GetString on something that isn't a string, or .GetInt32 on something that isn't an integer. I'd check the data types of the 'Student' table against your code to make sure you're using the right methods, though I've found .GetString doesn't seem to care about the data type so I may just be talking out of my rear end.
-
Nov 11th, 2006, 06:55 PM
#4
Thread Starter
New Member
Re: Casting Error??
Yes it was thank you i was using int32 instead of int64
-
Nov 12th, 2006, 10:10 AM
#5
Hyperactive Member
Re: Casting Error??
 Originally Posted by SaitStudent
Yes it was thank you i was using int32 instead of int64
Woo, yay! Can you mark the thread as resolved?
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
|