Imports System.Data
Imports System.Data.SqlClient
Public Class WebForm1
Inherits System.Web.UI.Page
'Protected WithEvents grdPatient As System.Web.UI.WebControls.DataGrid
'Declare a Connection object that is global in scope
Dim objConnection As SqlConnection
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
'Initialize the Connection Object...
objConnection = New SqlConnection("Server=TESTSQL1; Database=XRAY; Integrated Security=SSPI; Persist Security Info=False; Initial Catalog = XRAY; ") 'Trusted_Connection = True")
End Sub
Private Sub btnFindPatient_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindPatient.Click
'Declare Objects...
Dim objDataSet As DataSet
Dim objDataAdapter As SqlDataAdapter
Dim myCmd As SqlCommand
Dim myReader As SqlDataReader
Dim RsltMedRec As String
Dim RsltRad As String
Dim RsltPatient As String
Dim RsltSex As String
Dim RsltBirthDate As String
Dim RsltSocSec As String
Dim RsltLastExam As String
Dim strMed_REC As String
'Assign the value in the input box to the query variable
strMed_REC = txtGetMedRec.Text
'Create a SQL Command Object to query Patient by MedRec number
myCmd = objConnection.CreateCommand
myCmd.CommandText = "SELECT Med_Rec#, RAD#, First_Name," & _
"Last_Name, Sex, Birth_Date, Soc_Sec#, Last_Exam_Date " & _
"From tblPatient " & _
"WHERE Med_Rec#= '" & strMed_REC & "'"
objConnection.Open()
myReader = myCmd.ExecuteReader()
'Place the query Results into the result strings
Do While myReader.Read()
RsltMedRec = myReader.GetString(0)
RsltRad = myReader.GetString(1)
RsltPatient = myReader.GetString(3) & ", " & myReader.GetString(2)
RsltSex = myReader.GetString(4)
RsltBirthDate = myReader.GetString(5) & " "
RsltSocSec = myReader.GetString(6)
RsltLastExam = myReader.GetString(7)
Loop
'Display Results on the web form...
lblMedRec.Text = RsltMedRec
lblRad.Text = RsltRad
lblPatient.Text = RsltPatient
lblSex.Text = RsltSex
lblBirthDate.Text = RsltBirthDate
lblSocSec.Text = RsltSocSec
lblLastExam.Text = RsltLastExam
'Close(DataReader)
objConnection.Close()
'Set the SQL Query String to pull all the procedures...
objDataAdapter = New SqlDataAdapter("SELECT Proc_Date_Time as 'Proc Date/Time'," & _
"Dept, PROC#, Proc_Description As 'Proc Desc'," & _
"Ordering_Phy_Last As 'Order Phy LastName'," & _
"Ordering_Phy_Firs As 'Order Phy FirstName'" & _
"FROM tblProcedure WHERE Med_Rec# = '" & strMed_REC & "'" & _
"Order By Proc_Date_Time DESC", objConnection)
'Initialize the DataSet object and fill it...
objDataSet = New DataSet
objDataAdapter.Fill(objDataSet, "tblProcedure")
'Declare a DataView Object, populate it, and sort the data in it...
Dim objDataView As DataView = objDataSet.Tables("tblProcedure").DefaultView
grdPatient.DataSource = objDataView
grdPatient.DataBind()
'Close Connection
objConnection.Close()
End Sub
End Class