私はVB.NETでプロジェクトをやっています。3 つのテキスト ボックスとコマンド ボタンがあるフォームがあります。
TextBox1 (患者の登録番号) に値を入力し、コマンド ボタン (SearchButton) をクリックすると、SQL Server テーブルから値を検索し、結果を TextBox2 と TextBox3 (名前と患者の年齢)。
これは私がやったことですが、うまくいきません。
Dim cn As New SqlConnection
cn.ConnectionString = "Data source=localhost\SQLEXPRESS;Initial Catalog=hms;Integrated Security=True"
cn.Open()
Dim cm As New SqlCommand
cm.CommandText = "SELECT Patient_Name,Age FROM Patient_Prescrib"
cm.Connection = cn
Dim dr As SqlDataReader
dr = cm.ExecuteReader
If dr.HasRows Then
dr.Read()
' TextBox1.Text = dr.Item("Reg_No")
TextBox3.Text = dr.Item("Patient_Name")
TextBox4.Text = dr.Item("Age")
dr.Close()
End If
cn.Close()