 |
|
สอบถามปัญหา INNER JOIN 2 Fields รบกวนช่วยหน่อยครับ |
|
 |
|
|
 |
 |
|
ปัญหาคือ ผมจะดึงข้อมูล 1.Field (Bussiness) > table(MachineDocument)> Colum(MachineDocument1,MachineDocument,MachineDocument)
2.Filed (FSNEW) > Table (Car)> Colum(Car1,Car2,Car3,Car4)
ปัญหาตอนนี้ลอง run แล้ว แต่เรียกข้อมูลไม่ออกครับ พอจะมีวิธีช่วยไหม
Dim constr As String = "Data Source=TCJSRVDB02;Initial Catalog=BussinessApplication;User ID=sa"
Dim conFSNEW As String = "Data Source=TCJSRVDB02;Initial Catalog=FSNEW;User ID=sa"
Dim connection As New SqlConnection(constr)
If connection.State = ConnectionState.Closed Then
connection.Open()
End If
Dim connectionFSnew As New SqlConnection(conFSNEW)
If connectionFSnew.State = ConnectionState.Closed Then
connectionFSnew.Open()
End If
Dim consql As String = ""
Dim Reader As SqlDataReader
Dim Datatb As New System.Data.DataTable
consql = "SELECT CAR.car_id, CAR.car_type, CAR.car_model, CAR.car_serial, CAR.car_engineno, CAR.car_classic, " +
" MachineDocument.CarID, MachineDocument.Register_Car, MachineDocument.CheckMC_Doc, MachineDocument.CheckMC_Start, " +
" MachineDocument.CheckMC_End, MachineDocument.Car_Insurance_Doc, MachineDocument.Car_Insurance_DateEnd," +
" MachineDocument.Insurance_Doc, MachineDocument.Insurance_TypeDesc, MachineDocument.Insurance_CompanyDesc," +
" MachineDocument.Insurance_StartDate, MachineDocument.Insurance_EndDate" +
"FROM CAR INNER JOIN MachineDocument ON CAR.CAR_ID = MachineDocument.CarId "
Dim command As New SqlCommand(consql, connection)
Reader = command.ExecuteReader
Datatb.Load(Reader)
DataGridView1.DataSource = Datatb
DataGridView1.ReadOnly = True
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
code ครับ
Tag : .NET, Ms SQL Server 2012, Win (Windows App), VB.NET, VS 2015 (.NET 4.x)
|
ประวัติการแก้ไข 2020-12-09 08:58:30
|
 |
 |
 |
 |
Date :
2020-12-09 08:48:19 |
By :
chatchawan5897 |
View :
793 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
1. ควรครอบโค้ดให้อ่านง่ายหน่อย
2. ฝึกใช้ debug tools แล้วสังเกตค่าตัวแปรใน Local Windows
|
 |
 |
 |
 |
Date :
2020-12-13 21:05:42 |
By :
ล่องหน |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองทำ view ใน sql ดูนะครับจะสะดวกกว่าใน โค้ด
ถ้าใน .net ก็ลองใช้ datawizard ดู ก็จะเหมือนๆกับใน sql เช่นกัน
แต่ติดตรง sql สร้างครั้งเดียวจะใช้กี่โปรแกรมก็ได้ แต่ใน โค้ด เปลี่ยนโปรเจคใหม่ก็ต้องเขียนใหม่เรื่อยๆ
|
 |
 |
 |
 |
Date :
2020-12-16 21:37:33 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากๆครับ ผมทำได้แล้ว ทำใน sql เอา
|
 |
 |
 |
 |
Date :
2020-12-18 09:55:13 |
By :
chatchawan5897 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|