G
Guest
Hi Experts,
I have 2 tables in a dataset "ds", "Order" and "Customer". Order table
stores Customer ID; I want to show Customer Code in Customer table instead of
CustID in the combo box on a form data-binded to "Order". I code as following
and it works for other text control but not for the combo (Navigation button
works):
Dim constr As String =
ConfigurationSettings.AppSettings("SqlConnection1.ConnectionString")
Dim conn As New SqlConnection(constr)
Dim customer_comm As New SqlCommand("select * from tblCustomer", conn)
Dim order_da As New SqlDataAdapter("select * from tblorder", conn)
Dim customer_da As New SqlDataAdapter("select * from tblCustomer", conn)
Dim customer_read As SqlDataReader
Dim ds As New DataSet
Dim bm As BindingManagerBase
Private Sub frmOrder3_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
row = 0
If conn.State = ConnectionState.Closed Then conn.Open()
order_da.Fill(ds, "Order")
customer_da.Fill(ds, "Customer")
cbxCustomer.DataSource = ds
cbxCustomer.DisplayMember = "Customer.CustCode"
cbxCustomer.ValueMember = "Customer.CustID"
MsgBox(cbxCustomer.Items.Count, MsgBoxStyle.Information) 'it
shows 4
txtOrderID.DataBindings.Add("Text", ds, "Order.OrderID") 'works
cbxCustomer.DataBindings.Add("SelectedValue", ds, "Order.CustID")
txtPo_No.DataBindings.Add("Text", ds, "Order.po_no") 'works
bm = BindingContext(ds, "Order")
conn.Close()
If conn.State = ConnectionState.Closed Then conn.Open()
ds.Clear()
order_da.Fill(ds, "Order")
Catch ex As Exception
MsgBox("Error: " & ex.ToString, MsgBoxStyle.Exclamation)
End Try
End Sub
Private Sub btnNavNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNavNext.Click
bm.Position += 1
End Sub
Private Sub btnNavPrevious_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnNavPrevious.Click
bm.Position -= 1
End Sub
Thanks,
DAVIS_HK
I have 2 tables in a dataset "ds", "Order" and "Customer". Order table
stores Customer ID; I want to show Customer Code in Customer table instead of
CustID in the combo box on a form data-binded to "Order". I code as following
and it works for other text control but not for the combo (Navigation button
works):
Dim constr As String =
ConfigurationSettings.AppSettings("SqlConnection1.ConnectionString")
Dim conn As New SqlConnection(constr)
Dim customer_comm As New SqlCommand("select * from tblCustomer", conn)
Dim order_da As New SqlDataAdapter("select * from tblorder", conn)
Dim customer_da As New SqlDataAdapter("select * from tblCustomer", conn)
Dim customer_read As SqlDataReader
Dim ds As New DataSet
Dim bm As BindingManagerBase
Private Sub frmOrder3_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
row = 0
If conn.State = ConnectionState.Closed Then conn.Open()
order_da.Fill(ds, "Order")
customer_da.Fill(ds, "Customer")
cbxCustomer.DataSource = ds
cbxCustomer.DisplayMember = "Customer.CustCode"
cbxCustomer.ValueMember = "Customer.CustID"
MsgBox(cbxCustomer.Items.Count, MsgBoxStyle.Information) 'it
shows 4
txtOrderID.DataBindings.Add("Text", ds, "Order.OrderID") 'works
cbxCustomer.DataBindings.Add("SelectedValue", ds, "Order.CustID")
txtPo_No.DataBindings.Add("Text", ds, "Order.po_no") 'works
bm = BindingContext(ds, "Order")
conn.Close()
If conn.State = ConnectionState.Closed Then conn.Open()
ds.Clear()
order_da.Fill(ds, "Order")
Catch ex As Exception
MsgBox("Error: " & ex.ToString, MsgBoxStyle.Exclamation)
End Try
End Sub
Private Sub btnNavNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNavNext.Click
bm.Position += 1
End Sub
Private Sub btnNavPrevious_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnNavPrevious.Click
bm.Position -= 1
End Sub
Thanks,
DAVIS_HK