 |
|
ต้องการดึงข้อมูลจาก SQL 2 ตารางลงใน Datagride View และให้แสดงใน Text Box รบชี้แนะด้วยค่ะ VB.NET |
|
 |
|
|
 |
 |
|
ตอนนี้สามารถ ดึงข้อมูลจากตาราง 1 ตารางได้แล้ว
แต่ติดตรงที่ว่าจะดึงข้อมูลจากตารางที่ 2 ให้แสดงออกใน Datagride view
พอใช้คำสั่ง INNER JOIN กลับ Error
Err
Incorrect syntax near the keyword 'INNER'.
Incorrect syntax near 'Supplier'.
ไม่ทราบว่าต้องให้มันแสดงออกอย่างไร รบกวนด้วยคะ มีเทคนิคอย่างไรรบกวนชี้แจงให้ด้วยค่ะ
Code (VB.NET)
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"
Tmpsql &= " FROM Supplier"
Tmpsql &= " WHERE (((Supplier.Sup_Name)Like '" & Tmplist & "'));"
'Tmpsql = " SELECT Supplier.Sup_ID, Supplier.Sup_Name, Supplier.Sup_lastname, Bank.Bank_ID, Bank.Bank_AccountNumber, Bank.Bank_Name, Bank.Bank_Major"
'Tmpsql &= " 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("Bank").Rows(i).Item("Bank_ID").ToString.Trim
'tmpBankNumber = ds.Tables("Bank").Rows(i).Item("Bank.Bank_AccountNumber").ToString.Trim
'tmpBankName = ds.Tables("Bank").Rows(i).Item(" Bank.Bank_Name").ToString.Trim
'tmpBankMajor = ds.Tables("Bank").Rows(i).Item(" Bank.Bank_Major").ToString.Trim
Dim sDataRow As String() = {tmpSecId, tmpSecname, tmLastname, tmpSecadd, tmpBankId, tmpBankNumber, tmpBankName, tmpBankMajor}
DGV1.Rows.Add(sDataRow) 'เพิ่มตรงนี้เข้าไปคับ ก็ OK แล้ว
DGV1.ReadOnly = True
Tag : .NET, VB.NET, Windows
|
|
 |
 |
 |
 |
Date :
2015-09-22 12:11:07 |
By :
fonhaha |
View :
929 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เจอแล้วค่ะ ขอบคุณค่ะ
|
 |
 |
 |
 |
Date :
2015-09-22 13:35:51 |
By :
fonhaha |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เผื่อมีใครหาอยู่ เอาไว้ให้ค่ะ
  
Code (VB.NET)
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
|
 |
 |
 |
 |
Date :
2015-09-22 14:46:14 |
By :
fonhaha |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
   
|
 |
 |
 |
 |
Date :
2015-09-22 14:55:54 |
By :
fonfire |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2015-09-22 20:23:51 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|