Dim da As SqlDataAdapter
Dim ds As DataSet = New DataSet
Dim Tmpsql As String = ""
Dim gdvrow As New DataGridViewRow
Dim tmpSecId, tmpSecname, tmLastname, tmpSecadd, tmpBankId, tmpBankNumber, tmpBankName, tmpBankMajor As String
Tmpsql = " SELECT Supplier.Sup_ID, Supplier.Sup_Name, Supplier.Sup_lastname, Supplier.Sup_Address, Supplier.Bank_ID, Bank.Bank_AccountNumber, Bank.Bank_Name, Bank.Bank_Major"
Tmpsql &= " FROM Supplier INNER JOIN Bank ON Supplier.Bank_ID = Bank.Bank_ID"
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
tmLastname = ds.Tables("SUPPLIER").Rows(i).Item("SUP_LASTNAME").ToString.Trim
tmpSecadd = ds.Tables("SUPPLIER").Rows(i).Item("SUP_ADDRESS").ToString.Trim
tmpBankId = ds.Tables("SUPPLIER").Rows(i).Item("Bank_ID").ToString.Trim
tmpBankNumber = If(IsDBNull(ds.Tables("SUPPLIER").Rows(i).Item("Bank_AccountNumber")), "", Trim(ds.Tables("SUPPLIER").Rows(i).Item("Bank_AccountNumber")))
tmpBankName = If(IsDBNull(ds.Tables("SUPPLIER").Rows(i).Item("Bank_Name")), "", Trim(ds.Tables("SUPPLIER").Rows(i).Item("Bank_Name")))
tmpBankMajor = If(IsDBNull(ds.Tables("SUPPLIER").Rows(i).Item("Bank_Major")), "", Trim(ds.Tables("SUPPLIER").Rows(i).Item("Bank_Major")))
'
Dim sDataRow As String() = {tmpSecId, tmpSecname, tmLastname, tmpSecadd, tmpBankId, tmpBankNumber, tmpBankName, tmpBankMajor}
DGV1.Rows.Add(sDataRow) 'เพิ่มตรงนี้เข้าไปคับ ก็ OK แล้ว
DGV1.ReadOnly = True
End With