Private Sub FrmFindSup_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Tmplist As String = ""
If tmpSearch = "" Or tmpSearch Is DBNull.Value Then
Tmplist = "%"
Else
Tmplist = "%" & tmpSearch & "%"
End If
With Cn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strFn
.Open()
End With
Dim da As SqlDataAdapter
Dim ds As DataSet = New DataSet
Dim Tmpsql As String = ""
Dim gdvrow As New DataGridViewRow
Dim tmpSecId, tmpSecname, tmpSecadd As String
Tmpsql = "SUPPLIER.SUP_ID, SUPPLIER.SUP_NAME, SUPPLIER.SUP_ADDRESS"
Tmpsql &= " FROM SUPPLIER"
Tmpsql &= " WHERE (((SUPPLIER.SUP_NAME)Like '" & Tmplist & "'));"
If IsFind = True Then
ds.Tables("SUPPLIER").Clear()
End If
da = New SqlDataAdapter(Tmpsql, Cn)
da.Fill(ds, "SUPPLIER")
If ds.Tables("SUPPLIER").Rows.Count <> 0 Then
IsFind = True
For i As Integer = 0 To ds.Tables("SUPPLIER").Rows.Count - 1
With gdvrow
tmpSecId = ds.Tables("SUPPLIER").Rows(i).Item("SUP_ID").ToString.Trim
tmpSecname = ds.Tables("SUPPLIER").Rows(i).Item("SUP_NAME").ToString.Trim
tmpSecadd = ds.Tables("SUPPLIER").Rows(i).Item("SUP_ADDRESS").ToString.Trim
Dim sDataRow As String() = {tmpSecId, tmpSecname, tmpSecadd}
DGV1.Rows.Add(sDataRow) 'เพิ่มตรงนี้เข้าไปคับ ก็ OK แล้ว
DGV1.ReadOnly = True
End With
Next
Else
IsFind = False
DGV1.DataSource = Nothing
End If
If Not IsNothing(Cn) Then
If Cn.State = ConnectionState.Open Then
Cn.Close()
End If
Cn.Dispose()
End If
End Sub