|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Class as an arrayas an array. And if so how do i store data to it. I have listed my code below. Here's my code Public Shared Function LookupEmployeeByLastName(ByVal EmployeeLastName As String) As Employee() Dim EmployeeDS As New DataSet Dim EmpRecord() As Employee 'DIMENSION CLASS AS AN ARRAY Dim EmployeeTable As DataTable Const Strconn As String = "integrated security=SSPI;data source=GLENNL;initial catalog=BSGData" Dim Myconn As New SqlConnection(Strconn) Dim MyAdapter As New SqlDataAdapter _ ("Exec LookUpEmployeesByName @LastName", Myconn) MyAdapter.SelectCommand.Parameters.Add( _ "@LastName", SqlDbType.VarChar).Value = EmployeeLastName MyAdapter.Fill(EmployeeDS, "Employees") EmployeeTable = EmployeeDS.Tables(0) Dim anEmployee As DataRow Dim iRow, nRow As Integer nRow = EmployeeTable.Rows.Count For iRow = 0 To nRow - 1 anEmployee = EmployeeTable.Rows(iRow) EmpRecord(irow).FirstName = anEmployee.Item("FirstName") ' THIS IS WHERE I RUN INTO PROBLEMS Nexst Return EmpRecord
Show quote
Hide quote
"Glenn Lacampuenga" <gl***@wcs.ab.ca> wrote in message You have not dimensioned your EmpRecord array. You define it here:news:uPk1vnmKGHA.3728@tk2msftngp13.phx.gbl... : Still fairly new to vb.net and was wondering if it's possible to Dim a : class as an array. : And if so how do i store data to it. I have listed my code below. : : Here's my code : : Public Shared Function LookupEmployeeByLastName(ByVal EmployeeLastName As : String) As Employee() : : Dim EmployeeDS As New DataSet : : Dim EmpRecord() As Employee 'DIMENSION CLASS AS AN ARRAY : : Dim EmployeeTable As DataTable : : Const Strconn As String = "integrated security=SSPI;data : source=GLENNL;initial catalog=BSGData" : : Dim Myconn As New SqlConnection(Strconn) : : Dim MyAdapter As New SqlDataAdapter _ : : ("Exec LookUpEmployeesByName @LastName", Myconn) : : MyAdapter.SelectCommand.Parameters.Add( _ : : "@LastName", SqlDbType.VarChar).Value = EmployeeLastName : : MyAdapter.Fill(EmployeeDS, "Employees") : : EmployeeTable = EmployeeDS.Tables(0) : : Dim anEmployee As DataRow : : Dim iRow, nRow As Integer : : nRow = EmployeeTable.Rows.Count : : For iRow = 0 To nRow - 1 : : anEmployee = EmployeeTable.Rows(iRow) : : EmpRecord(irow).FirstName = anEmployee.Item("FirstName") ' THIS IS WHERE : I RUN INTO PROBLEMS : : Nexst : : Return EmpRecord Dim EmpRecord() As Employee 'DIMENSION CLASS AS AN ARRAY but you never state it's size. An array has a fixed length and you must specify it at some point. What you need is something along these lines: (Caution: untested) nRow = EmployeeTable.Rows.Count ReDim EmpRecord(nRow - 1) For iRow = 0 To nRow - 1 Ralf -- -- ---------------------------------------------------------- * ^~^ ^~^ * * _ {~ ~} {~ ~} _ * * /_``>*< >*<''_\ * * (\--_)++) (++(_--/) * ---------------------------------------------------------- There are no advanced students in Aikido - there are only competent beginners. There are no advanced techniques - only the correct application of basic principles.
Combobox in VB2005
Newbie Question 2, Reference To Controls On A Form problem with relative paths in VS/VB.net making image click fire codebehind function? newbie problem with array Problem Communicating Between Forms Calling Program A from Program B help with multiple forms on asp.net 1.1 page, please Newbie Question Saving Projects late bound form reference |
|||||||||||||||||||||||