Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i am new to ASP.net
I'm encountering a problem when i changed my Array from using a definite value of 4 to a value specified by the user held in the integer variable *num*.
When i click the next button, this error occurs; "THERE IS NO ROW IN POSITION 1"
Please help urgently. Below is a snippet of my code:

VB
dim nums as String = Request("marks")

           If Not Int32.TryParse(nums, num) Then

               For i = 0 To num
                   cmd.CommandText = "select * from test where Serial=" & a(i)
                   adp = New SqlDataAdapter(cmd.CommandText, cnn)
                   adp.Fill(ds, "test")
               Next

           End If







           cnn.Close() 'connection closed


           'this code is for creating new a table "preferably ANSWERED TABLE"
           dt = New DataTable("Answered")
           dt.Columns.Add("Serial", GetType(Integer))
           dt.Columns.Add("question", GetType(String))
           dt.Columns.Add("choice1", GetType(String))
           dt.Columns.Add("choice2", GetType(String))
           dt.Columns.Add("choice3", GetType(String))
           dt.Columns.Add("choice4", GetType(String))
           dt.Columns.Add("correct", GetType(String))
           dt.Columns.Add("selected", GetType(Integer))


           'this code is for adding to the table TEST
           Dim r As DataRow

           For Each r In ds.Tables("test").Rows
               dr = dt.NewRow
               dr("Serial") = dt.Rows.Count + 1
               dr("question") = r.Item("question")
               dr("choice1") = r.Item("choice1")
               dr("choice2") = r.Item("choice2")
               dr("choice3") = r.Item("choice3")
               dr("choice4") = r.Item("choice4")
               dr("correct") = r.Item("correct")
               dr("selected") = -1
               dt.Rows.Add(dr)

           Next

           Session("Answered") = dt

           Call show()

           If ctr = 0 Then
               BtnPrev.Enabled = False


           End If


       End If
   End Sub
   Sub show()
       dt = Session("Answered")
       Dim v As View = Me.View1


       Dim l As Label
       l = CType(v.FindControl("Label1"), Label)
       l.Text = dt.Rows(ctr).Item("Serial") & "."
       l = CType(v.FindControl("Label2"), Label)
       l.Text = dt.Rows(ctr).Item("question")



       Dim r As RadioButtonList
       r = CType(v.FindControl("RadioButtonList1"), RadioButtonList)
       r.Items.Clear()
       r.Items.Add(dt.Rows(ctr).Item("choice1"))
       r.Items.Add(dt.Rows(ctr).Item("choice2"))
       r.Items.Add(dt.Rows(ctr).Item("choice3"))
       r.Items.Add(dt.Rows(ctr).Item("choice4"))
       r.SelectedIndex = dt.Rows(ctr).Item("selected")



       Session("ctr") = ctr
   End Sub
Posted
Updated 23-Feb-13 1:56am
v3
Comments
[no name] 23-Feb-13 7:56am    
check your query first. it means your query does not fetch any data for your condition.
OsoJames 23-Feb-13 8:04am    
Before this was my code for Redirect:

Response.Redirect("QuickStart.aspx?marks=" & label1.text)

Currently it is:
Marks = Cint(label1.text)
Response.Redirect("QuickStart.aspx?marks=" & marks)

and the current one is giving error that, "Conversion from string "Label" to type 'Integer' is not valid."
OsoJames 1-Mar-13 6:02am    
Exactly, you were right

1 solution

I see you have written this:
VB
Dim l As Label
l = CType(v.FindControl("Label1"), Label)
l.Text = dt.Rows(ctr).Item("Serial") & "."
l = CType(v.FindControl("Label2"), Label)
l.Text = dt.Rows(ctr).Item("question")

You have changed the Label1's text and it does not look like an integer. When you explicitly tried it to convert it directly into an integer you got type cast exception. Please DEBUG and you can see for yourself, what is the value of 'label1.Text' and make sure it has the value that you intend it to have.
 
Share this answer
 
Comments
OsoJames 23-Feb-13 10:35am    
dim nums as String = Request("marks")

that's where the problem resides, i guess it not doing what i want it to do. So i changed it from that to:
num = Val(Request.QueryString("marks"))

i want to convert the string value of marks to a numeric value (integer) but it seems this is still not doing the job. Because it is the for loop that is not working, if only this would work problem would be solved
OsoJames 1-Mar-13 6:02am    
Thanks. I've solved it
I was using the wrong textbox to send the value i wanted.
Sandeep Mewara 1-Mar-13 6:14am    
Good to know you resolved.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900