我是VB.net的初学者,我正面临这个问题。 鼠标点击网格视图如何同时显示所有组合框中的两个表格字段 我使用MS Access 2013作为数据库和VS2015 ...
答案 0 :(得分:0)
我有一个答案,想在这里分享,这可能对某人有帮助
Sub showTable1() Using con As New OleDbConnection("provider=microsoft.ace.oledb.12.0; data source=TestDB.accdb;jet oledb:database password=yourpassword") con.Open() Using cmd As New OleDbCommand cmd.Connection = con ''## cmd.CommandText = "SELECT * FROM Table1 " & "WHERE Patient_no = @Patient_no" cmd.Parameters.Add("@Patient_no", OleDbType.Integer).Value = CInt(Val(Me.cbxSearch.Text)) Using dt As New DataTable dt.Load(cmd.ExecuteReader) If dt.Rows.Count > 0 Then txtNo.Text = (dt.Rows(0).Item("Patient_no")).ToString cbxPatName.Text = dt.Rows(0).Item("Name").ToString cbxAddress.Text = dt.Rows(0).Item("Address").ToString DTPicker.Text = (dt.Rows(0).Item("Birthdate")).ToString txtAge.Text = dt.Rows(0).Item("Age").ToString txtPhone.Text = dt.Rows(0).Item("Phone").ToString cbxHusband.Text = dt.Rows(0).Item("HusName").ToString End If End Using End Using End Using End Sub <code>
Sub ShowTable2() Using con As New OleDbConnection("provider=microsoft.ace.oledb.12.0; data source=TestDB.accdb;jet oledb:database password=yourpassword") con.Open() Using cmd As New OleDbCommand cmd.Connection = con cmd.CommandText = "SELECT * FROM Table2 WHERE Patient_no = @Patient_no" cmd.Parameters.Add("@Patient_no", OleDbType.Integer).Value = CInt(Val(txtNo.Text)) Using dt As New DataTable dt.Load(cmd.ExecuteReader) If dt.Rows.Count > 0 Then txtVis.Text = dt.Rows(0).Item("Vis_no").ToString txtNo.Text = dt.Rows(0).Item("Patient_no").ToString cbxGL.Text = dt.Rows(0).Item("GL").ToString cbxPuls.Text = dt.Rows(0).Item("Pls").ToString cbxBP.Text = dt.Rows(0).Item("BP").ToString cbxWeight.Text = dt.Rows(0).Item("Wt").ToString cbxBodyBuilt.Text = dt.Rows(0).Item("BdBt").ToString cbxChtH.Text = dt.Rows(0).Item("ChtH").ToString cbxHdNe.Text = dt.Rows(0).Item("HdNe").ToString cbxExt.Text = dt.Rows(0).Item("Ext").ToString cbxFunL.Text = dt.Rows(0).Item("FunL").ToString cbxScars.Text = dt.Rows(0).Item("Scrs").ToString cbxEdema.Text = dt.Rows(0).Item("Edm").ToString cbxUS.Text = dt.Rows(0).Item("US").ToString txtAmount.Text = dt.Rows(0).Item("Amount").ToString DTPickerAtt.Text = dt.Rows(0).Item("AttDt").ToString End If End Using End Using End Using End Sub
您必须将这两段代码放在网格视图的单击鼠标事件上,以便通过单击网格视图同时显示两个表内容