Can anyone tell me the best method to pick a record from a database using ExecuteReader, and passing it into an arraylist or any collection. I basically want to store all the records into a collection, arraylist or dictionary and then use that to display data.
Currently i have a class, with properties corresponding to the fields, storing them into those properties, and then adding every instance into an ArrayList. Is it possible to access individual properties from the object added to the arraylist, or am i completely in the wrong direction
While objReader.Read
mcp.SurveyQuestion = objReader.GetString(2)
mcp.Option1 = IIf(IsDBNull(objReader.GetValue(3)), " ", objReader.GetString(3))
mcp.Option2 = IIf(IsDBNull(objReader.GetValue(4)), " ", objReader.GetValue(4).ToString)
mcp.Option3 = IIf(IsDBNull(objReader.GetValue(5)), " ", objReader.GetValue(5).ToString)
mcp.Option4 = IIf(IsDBNull(objReader.GetValue(6)), " ", objReader.GetValue(6).ToString)
mcp.Option5 = IIf(IsDBNull(objReader.GetValue(7)), " ", objReader.GetValue(7).ToString)
questionairre.Add(mcp)
End While
where mcp is the instance of the class and questionairre is the Arraylist where i am adding the instance of the object.
Is this a feasible way??
Currently i have a class, with properties corresponding to the fields, storing them into those properties, and then adding every instance into an ArrayList. Is it possible to access individual properties from the object added to the arraylist, or am i completely in the wrong direction
While objReader.Read
mcp.SurveyQuestion = objReader.GetString(2)
mcp.Option1 = IIf(IsDBNull(objReader.GetValue(3)), " ", objReader.GetString(3))
mcp.Option2 = IIf(IsDBNull(objReader.GetValue(4)), " ", objReader.GetValue(4).ToString)
mcp.Option3 = IIf(IsDBNull(objReader.GetValue(5)), " ", objReader.GetValue(5).ToString)
mcp.Option4 = IIf(IsDBNull(objReader.GetValue(6)), " ", objReader.GetValue(6).ToString)
mcp.Option5 = IIf(IsDBNull(objReader.GetValue(7)), " ", objReader.GetValue(7).ToString)
questionairre.Add(mcp)
End While
where mcp is the instance of the class and questionairre is the Arraylist where i am adding the instance of the object.
Is this a feasible way??