ขอคำแนะนำหน่อยครับ form load ต้องการดึงข้อมูลมา 2 table มาใส่อย่างละตัวของ combobox1 และ combobox2
มันไม่ยอมแสดงอะครับ ขอบคุณครับ ดังรูปภาพ
Code
Imports MySql.Data.MySqlClient
Public Class Frm_bill
Dim MysqlConn As MySqlConnection
Dim COMMAND As MySqlCommand
Dim COMMAND1 As MySqlCommand
Dim datememo As String
Private Sub Frm_bill_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
datememo = Date.Today.ToString("dd/MM/yyyy")
date_memo.Text = datememo
MysqlConn = New MySqlConnection
MysqlConn.ConnectionString = "Server=localhost;User Id=root;Password=p@ssw0rd;Database=db_bill"
Dim READER As MySqlDataReader
Dim READER1 As MySqlDataReader
Try
MysqlConn.Open()
Dim Query As String
Query = "SELECT * FROM company"
COMMAND = New MySqlCommand(Query, MysqlConn)
READER = COMMAND.ExecuteReader
While READER.Read
Dim name_cpth = READER.GetString("name_cpth")
ComboBox1.Items.Add(name_cpth)
End While
Catch ex As MySqlException
MessageBox.Show(ex.Message)
End Try
Try
MysqlConn.Open()
Dim Query1 As String
Query1 = "SELECT * FROM customer"
COMMAND1 = New MySqlCommand(Query1, MysqlConn)
READER1 = COMMAND1.ExecuteReader
While READER1.Read
Dim name_ctth = READER1.GetString("name_ctth")
ComboBox2.Items.Add(name_ctth)
End While
Catch ex As MySqlException
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
MysqlConn = New MySqlConnection
MysqlConn.ConnectionString = "Server=localhost;User Id=root;Password=p@ssw0rd;Database=db_bill"
Dim READER As MySqlDataReader
Try
MysqlConn.Open()
Dim Query As String
date_memo.Text = Date.Today.ToString("yyyy-MM-dd")
Query = "SELECT * FROM company WHERE name_cpth = '" & ComboBox1.Text & "'"
COMMAND = New MySqlCommand(Query, MysqlConn)
READER = COMMAND.ExecuteReader
While READER.Read
CPN_id_company.Text = READER.GetString("id_company")
CPN_name_cpth.Text = READER.GetString("name_cpth")
CPN_address_cpth.Text = READER.GetString("address_cpth")
CPN_telephone.Text = READER.GetString("telephone")
CPN_mobile.Text = READER.GetString("mobile")
CPN_fax.Text = READER.GetString("fax")
CPN_tex.Text = READER.GetString("tex")
End While
Catch ex As MySqlException
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
MysqlConn = New MySqlConnection
MysqlConn.ConnectionString = "Server=localhost;User Id=root;Password=p@ssw0rd;Database=db_bill"
Dim READER1 As MySqlDataReader
Try
MysqlConn.Open()
Dim Query1 As String
date_memo.Text = Date.Today.ToString("yyyy-MM-dd")
Query1 = "SELECT * FROM customer WHERE name_ctth = '" & ComboBox2.Text & "'"
COMMAND1 = New MySqlCommand(Query1, MysqlConn)
READER1 = COMMAND1.ExecuteReader
While READER1.Read
CTM_id_customer.Text = READER1.GetString("id_customer")
CTM_name_ctth.Text = READER1.GetString("name_ctth")
CTM_address_ctth.Text = READER1.GetString("address_ctth")
CTM_telephone.Text = READER1.GetString("telephone")
CTM_mobile.Text = READER1.GetString("mobile")
CTM_fax.Text = READER1.GetString("fax")
CTM_tex.Text = READER1.GetString("tex")
End While
Catch ex As MySqlException
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
Tag : .NET, Crystal Report, Web (ASP.NET), VB.NET, C#