LOOPING ERROR IN DATAGRIDVIEW ROWS

  • Thread starter Thread starter clynnekent
  • Start date Start date
C

clynnekent

Guest
Good day everyone, I just wan't to ask about DataGridView. Everytime I search using Textbox I have an error looping in my DataGrid here is my sample program that I make..

FOR FORM LOAD

Private Sub frmproductsearch_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
connection.conn()
cn.Open()
ds.Clear()
Dim ctr, i As Integer
str = "Select * from tblproduct"
cmd = New OleDbCommand(str, cn)
da.SelectCommand = cmd
da.Fill(ds, "tblproduct")

ctr = ds.Tables("tblproduct").Rows.Count - 1
For i = 0 To ctr
DataGridView1.Rows.Add(ds.Tables("tblproduct").Rows(i)(0).ToString, ds.Tables("tblproduct").Rows(i)(1).ToString, ds.Tables("tblproduct").Rows(i)(2).ToString, ds.Tables("tblproduct").Rows(i)(3).ToString, ds.Tables("tblproduct").Rows(i)(4).ToString, ds.Tables("tblproduct").Rows(i)(5).ToString, ds.Tables("tblproduct").Rows(i)(6).ToString, ds.Tables("tblproduct").Rows(i)(7).ToString)

Next
cn.Close()
End Sub



------------------------------------------------------------------------------------

FOR TEXTBOX SEARCH

Private Sub txtproductsearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtproductsearch.TextChanged
connection.conn()
cn.Open()
ds.Clear()
Dim ctr, i As Integer
str = "Select * from tblproduct where Prod_name like '%" & txtproductsearch.Text & "%'"
cmd = New OleDbCommand(str, cn)
da.SelectCommand = cmd
da.Fill(ds, "tblproduct")
ctr = ds.Tables("tblproduct").Rows.Count - 1
For i = 0 To ctr
DataGridView1.Rows.Add(ds.Tables("tblproduct").Rows(i)(0).ToString, ds.Tables("tblproduct").Rows(i)(1).ToString, ds.Tables("tblproduct").Rows(i)(2).ToString, ds.Tables("tblproduct").Rows(i)(3).ToString, ds.Tables("tblproduct").Rows(i)(4).ToString, ds.Tables("tblproduct").Rows(i)(5).ToString, ds.Tables("tblproduct").Rows(i)(6).ToString, ds.Tables("tblproduct").Rows(i)(7).ToString)
Next

cn.Close()
End Sub

Continue reading...
 
Back
Top