If e.KeyChar = Chr(13) Then
Dim cnntemp As New OleDbConnection("provider = Microsoft.jet.oledb.4.0; data source=..\prms_database.mdb")
Dim acctemp As String
Dim da2temp As New OleDb.OleDbDataAdapter
Dim objcommandtemp As New OleDb.OleDbCommand
Dim ds2temp As New DataSet
acctemp = "select * from prms_patient where pat_patno = '" & mtbPatNo.Text & "'"
da2temp = New OleDb.OleDbDataAdapter(acctemp, cnntemp)
da2temp.Fill(ds2temp, "temp")
cnntemp.Close()
If ds2temp.Tables("temp").Rows.Count = 0 Then
MessageBox.Show("Invalid Patient or Family Number!", "Try Again", MessageBoxButtons.OK)
Return
Else
Dim cnn2 As New OleDb.OleDbConnection("provider = Microsoft.jet.oledb.4.0; data source=..\prms_database.mdb")
Dim acc As String
Dim da2 As New OleDb.OleDbDataAdapter
Dim objcommand As New OleDb.OleDbCommand
Dim ds2 As New DataSet
'Dim temp As String
acc = "select * from prms_patient where pat_patno = '" & mtbPatNo.Text & "'"
da2 = New OleDb.OleDbDataAdapter(acc, cnn2)
da2.Fill(ds2, "temp")
cnn2.Close()
If ds2.Tables("temp").Rows.Count > 0 Then
tbFN.Text = ds2.Tables("temp").Rows(0).Item("pat_fn").ToString
cbMI.SelectedItem = ds2.Tables("temp").Rows(0).Item("pat_mi").ToString
tbSN.Text = ds2.Tables("temp").Rows(0).Item("pat_sn").ToString
tbAdd.Text = ds2.Tables("temp").Rows(0).Item("pat_add").ToString
If Trim(ds2.Tables("temp").Rows(0).Item("pat_gender").ToString) = "Male" Then
rbMale.Select()
Else
rbFemale.Select()
End If
cbStat.SelectedItem = ds2.Tables("temp").Rows(0).Item("pat_stat").ToString
mtbMobile.Text = ds2.Tables("temp").Rows(0).Item("pat_mobile").ToString
mtbLand.Text = ds2.Tables("temp").Rows(0).Item("pat_landline").ToString
pbox.ImageLocation = ds2.Tables("temp").Rows(0).Item("pat_pic").ToString
End If
End If
End If
In other words, Fill a dataset based on a query result and...
If it returns 0 rows then
Notify the user that the ID was invalid.
Else 'So it returned more than 0 rows so now we know that query worked
'create all new Data Objects and perform the same query to fill yet another dataset
'then if the row count (once again) is above 0 then
'populate the textboxes.
...
This post has been edited by CharlieMay: 15 February 2012 - 10:01 AM

New Topic/Question
Reply




MultiQuote





|