You must Sign In to post a response.
  • Category: ASP.NET

    There is Not at Position 1

    i have creating dynamic labels vb.net using visualstudio 2010 and when bind data from sqltables Error is occured below is coding

    dt = New DataTable
    da = New SqlDataAdapter("select RichEditor from PPT_CCM_ToolTipEditor", con)
    da.Fill(dt)
    If dt.Rows.Count > 0 Then
    For i As Integer = 0 To dt.Rows.Count - 1
    For j As Integer = 1 To 4
    Dim label As New Label()
    label.ID = "Label" & j
    label.Text = dt.Rows(i).ToString().....> erro occured this place There is no row at position 1.....
    PlaceHolder1.Controls.Add(label)
    Next
    DirectCast(PlaceHolder1.FindControl("label1"), Label).Text = "<br/>"
    DirectCast(PlaceHolder1.FindControl("label2"), Label).Text = "<br/>"
    DirectCast(PlaceHolder1.FindControl("label3"), Label).Text = "<br/>"
    DirectCast(PlaceHolder1.FindControl("label4"), Label).Text = "<br/>"

    Next
    End If
  • #724820
    Hi selvakumar,

    The error clearly suggests you there is no row at position 1 in your DataTable.

    Please check that conditon properly put a break point and check line by line, then you found the solution by your self.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #724827
    Hi,

    Your code is already check dt have data or not but you cannot get item value properly mean not mention which column value. Rewrite your error line like below


    label.Text = dt.Rows(i)(0).ToString() '0 is column index change it as per your required column

    Regards
    N.Ravindran
    Your Hard work never fails

  • #724830
    The error clearly suggest that the column or row you are trying to access is not present.

    its better forst check the count of the rows or column you are expecting and then read the values from it.

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.