Dear Experts

Table gpass has data as
gate-----date-----c----bno----acccode----tittle----weight-------qty
1----18/01/2010---a----2--------2----------abc-----10.00-------15

Then there are two textbox having values as

txtgat.text=1
txtdat.text=18/01/2010

I these codes and it generates error message as

ArgumentOutOfRangeException was unhandled.
Idex was out of range. Must be non-negative and less than the size of collection. Parameter name: Index

What mistake I am doing, please modify

Private Sub txtGat_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtGat.TextChanged
        If Len(Me.txtGat.Text) > 0 AndAlso Me.txtDat.Text IsNot Nothing Then

            str = "Select * from gpass where vou_no= " & Val(Me.txtGat.Text) & " And Date =   '" & Me.txtDat.Text & "'"
            dt = GetTable(str)

            If (dt.Rows.Count > 0) Then
                Me.txtCir.Text = dt.Rows(0)("c")
                Me.txtVou.Text = dt.Rows(0)("bno")
                cmd.ExecuteNonQuery()

            End If


            For i = 0 To dt.Rows.Count -1
                Me.DataGridView1.Rows.Add()
                Me.DataGridView1.Rows(i).Cells(0).Value = Val(dt.Rows(i).Item(1))
                Me.DataGridView1.Rows(i).Cells(1).Value = Trim(dt.Rows(i).Item(2))
                Me.DataGridView1.Rows(i).Cells(2).Value = Val(dt.Rows(i).Item(3))
                Me.DataGridView1.Rows(i).Cells(3).Value = Val(dt.Rows(i).Item(4))
            Next

        End If
    End Sub

would you please the next time you have an error msg just tell the number of line it's shown on

anyways ......... from the code you provided the msg could be raised at the line number 17

make sure that the DataGridView has Columns already added ,
or you can assign the DataTable to DataGridView.DataSource,
this would make your life easier

Me.DataGridView1.DataSource = dt

hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.