Monday, March 26, 2012

fetching data in a datatable

hello, i'm using asp.net 2 with VB, i have a table in my db named 'exams' and i have 6 columns in this table one for question number and one for the question and 3 columns for 3 answers and a last column for the right answer, now in my page i want to show 7 questions and each question has 3 answers that i can choose between them i want the question appear in datatable and the answers in radiolist i have a little code for that but it shows an error it says "no row at position 1" so hope u guys can help :

Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\aspnetdb.mdf;Integrated Security=True;User Instance=True")
Dim a As New ArrayList(8)
Dim i As New Integer
i = 0
Dim d As New DataSet()
Dim cmd As New SqlDataAdapter("select top(7) question from exams", con)
cmd.Fill(d, "exams")
a.Add(d.Tables.Item(0, 1))
i = i + 1
Dim ta As New DataTable
ta.Rows(i).Item(0).text = d.Tables(0).Rows(0)(i)

and by the way this code is for the questions i still dont have the code for the answers that will appear in a radiolist hope u can help .thanksnobody can help?!!!!|||Are you sure the sql query did return result?
This error always occurs if you specify an index that is out of range.sql

No comments:

Post a Comment