critera表达式中的数据类型不匹配 [英] Data type mismatch in critera expression
问题描述
有人可以告诉我我在做什么错吗?
can somebody tell me what I am doing wrong?
If TabControl.SelectedTab Is PatientData_TabPage Then
conn.ConnectionString = My.Settings.ConnectionString
PatientID = PatientID_ToolStripLabel.Text
Try
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
If Male_RadioButton.Checked = True Then
Gender = "Male"
ElseIf Female_RadioButton.Checked = True Then
Gender = "Female"
End If
If UMCYes_RadioButton.Checked = True Then
Under_Medical_Care = True
ElseIf UMCNo_RadioButton.Checked = True Then
Under_Medical_Care = False
End If
If DiabeticYes_RadioButton.Checked = True Then
Diabetic = True
ElseIf DiabeticNo_RadioButton.Checked = True Then
Diabetic = False
End If
If AnemicYes_RadioButton.Checked = True Then
Anemic = True
ElseIf AnemicNo_RadioButton.Checked = True Then
Anemic = False
End If
If FreqColdsYes_RadioButton.Checked = True Then
FrequentColds = True
ElseIf FreqColdsNo_RadioButton.Checked = True Then
FrequentColds = False
End If
If SurgeryTonsilsYes_RadioButton.Checked = True Then
SurgeryTonsils = True
ElseIf SurgeryTonsilsNo_RadioButton.Checked = True Then
SurgeryTonsils = False
End If
If SurgeryAdenoidsYes_RadioButton.Checked = True Then
SurgeryAdenoids = True
ElseIf SurgeryAdenoidsNo_RadioButton.Checked = True Then
SurgeryAdenoids = False
End If
If SnckBtwMealsYes_CheckBox.Checked = True Then
SnackBetweenMeals = True
ElseIf SnckBtwMealsNo_CheckBox.Checked = False Then
SnackBetweenMeals = False
End If
If EatMnySweetsYes_CheckBox.Checked = True Then
EatManySweets = True
ElseIf EatMnySweetsNo_CheckBox.Checked = True Then
EatManySweets = False
End If
If EatRawVeggiesYes_CheckBox.Checked = True Then
SnackBetweenMeals = True
ElseIf EatRawVeggiesNo_CheckBox.Checked = True Then
SnackBetweenMeals = False
End If
If EatFreshFruitsYes_CheckBox.Checked = True Then
SnackBetweenMeals = True
ElseIf EatFreshFruitsNo_CheckBox.Checked = True Then
SnackBetweenMeals = False
End If
If HOIYes_CheckBox.Checked = True Then
SnackBetweenMeals = True
ElseIf HOINo_CheckBox.Checked = True Then
SnackBetweenMeals = False
End If
If TTE_CheckBox.Checked = True Then
TTE = True
ElseIf TTE_CheckBox.Checked = True Then
TTE = False
End If
If TTP_CheckBox.Checked = True Then
TTP = True
ElseIf TTP_CheckBox.Checked = True Then
TTP = False
End If
If NBE_CheckBox.Checked = True Then
NBE = True
ElseIf NBE_CheckBox.Checked = True Then
NBE = False
End If
If NBP_CheckBox.Checked = True Then
NBP = True
ElseIf NBP_CheckBox.Checked = True Then
NBP = False
End If
If LBE_CheckBox.Checked = True Then
LBE = True
ElseIf LBE_CheckBox.Checked = True Then
LBE = False
End If
If LBP_CheckBox.Checked = True Then
LBP = True
ElseIf LBP_CheckBox.Checked = True Then
LBP = False
End If
If TSE_CheckBox.Checked = True Then
TSE = True
ElseIf TSE_CheckBox.Checked = True Then
TSE = False
End If
If TSP_CheckBox.Checked = True Then
TSP = True
ElseIf TSP_CheckBox.Checked = True Then
TSP = False
End If
If BE_CheckBox.Checked = True Then
BE = True
ElseIf BE_CheckBox.Checked = True Then
BE = False
End If
If BP_CheckBox.Checked = True Then
BP = True
ElseIf BP_CheckBox.Checked = True Then
BP = False
End If
If MBE_CheckBox.Checked = True Then
MBE = True
ElseIf MBE_CheckBox.Checked = True Then
MBE = False
End If
Dim MBP As Boolean
If MBP_CheckBox.Checked = True Then
MBP = True
ElseIf MBP_CheckBox.Checked = True Then
MBP = False
End If
If PhotoYes_Checkbox.Checked = True Then
Photographs = True
ElseIf PhotoNo_CheckBox.Checked = True Then
Photographs = False
End If
If BrushingYes_CheckBox.Checked = True Then
Photographs = True
ElseIf BrushingNo_CheckBox.Checked = True Then
Photographs = False
End If
If DietCounsellingYes_CheckBox.Checked = True Then
Photographs = True
ElseIf DietCounsellingNo_CheckBox.Checked = True Then
Photographs = False
End If
If LAFYES_CheckBox.Checked = True Then
Photographs = True
ElseIf LAFNO_CheckBox.Checked = True Then
Photographs = False
End If
'Add data to the Patients table
Dim cmdAddPatients As New OleDbCommand("Insert into `Patients` (`ID`, `Patient_Name`, `Patient_Gender`) VALUES (?, ?, ?)", conn)
cmdAddPatients.Parameters.Add(New OleDbParameter("ID", PatientID))
cmdAddPatients.Parameters.Add(New OleDbParameter("Patient_Name", PatientName_TextBox.Text))
cmdAddPatients.Parameters.Add(New OleDbParameter("Patient_Gender", Gender))
cmdAddPatients.ExecuteNonQuery()
DataTable_patients.AcceptChanges()
conn.Close()
conn.Open()
'Adde data to the Patient Details table
Dim cmdAddPatient_Details As New OleDbCommand("Insert into `Patient_Details` (`ID`, `Parents_Name`, `DOB`, `School`) VALUES (?, ?, ?, ?)", conn)
cmdAddPatient_Details.Parameters.Add(New OleDbParameter("ID", PatientID))
cmdAddPatient_Details.Parameters.Add(New OleDbParameter("Parents_Name", ParentName_TextBox.Text))
cmdAddPatient_Details.Parameters.Add(New OleDbParameter("DOB", Trim(Format(Age_DateTimePicker.Value, "hh:mm tt"))))
cmdAddPatient_Details.Parameters.Add(New OleDbParameter("School", School_TextBox.Text))
cmdAddPatient_Details.ExecuteNonQuery()
DataTable_patient_details.AcceptChanges()
conn.Close()
conn.Open()
'Add edited data to the Patient Contact Details table
Dim cmdAddPatient_Contact_Details As New OleDbCommand("Insert into `Patient_Contact_Details` (`ID`, `ContactNo_Residence`, `ContactNo_Mobile`, `ContactNo_Office`, `Address`, `Email`) VALUES (?, ?, ?, ?, ?, ?)", conn)
cmdAddPatient_Contact_Details.Parameters.Add(New OleDbParameter("ID", PatientID_ToolStripLabel.Text))
cmdAddPatient_Contact_Details.Parameters.Add(New OleDbParameter("ContactNo_Residence", ResidenceNo_TextBox.Text))
cmdAddPatient_Contact_Details.Parameters.Add(New OleDbParameter("ContactNo_Mobile", MobileNo_TextBox.Text))
cmdAddPatient_Contact_Details.Parameters.Add(New OleDbParameter("ContactNo_Office", OfficeNo_ComboBox.SelectedText))
cmdAddPatient_Contact_Details.Parameters.Add(New OleDbParameter("Address", Address_TextBox.Text))
cmdAddPatient_Contact_Details.Parameters.Add(New OleDbParameter("Email", Email_TextBox.Text))
cmdAddPatient_Contact_Details.ExecuteNonQuery()
DataTable_patient_contact_details.AcceptChanges()
conn.Close()
conn.Open()
'Add edited data to the Medical History table
Dim cmdAddPatient_Medical_History As New OleDbCommand("Insert into `Medical_History` (`ID`, `UnderMedCare`, `Anemic`, `Diabetic`, `Allergies`, `FrequentColds`, `TonsilsSurgeryDone`, `AdenoidsSurgeryDone`, `Medication`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", conn)
cmdAddPatient_Medical_History.Parameters.Add(New OleDbParameter("ID", PatientID_ToolStripLabel.Text))
cmdAddPatient_Medical_History.Parameters.Add(New OleDbParameter("UnderMedCare", Under_Medical_Care))
cmdAddPatient_Medical_History.Parameters.Add(New OleDbParameter("Anemic", Anemic))
cmdAddPatient_Medical_History.Parameters.Add(New OleDbParameter("Diabetic", Diabetic))
cmdAddPatient_Medical_History.Parameters.Add(New OleDbParameter("Allergies", Allergies.ToString))
cmdAddPatient_Medical_History.Parameters.Add(New OleDbParameter("FrequentColds", FrequentColds))
cmdAddPatient_Medical_History.Parameters.Add(New OleDbParameter("TonsilsSurgeryDone", SurgeryTonsils))
cmdAddPatient_Medical_History.Parameters.Add(New OleDbParameter("AdenoidsSurgeryDone", SurgeryAdenoids))
cmdAddPatient_Medical_History.Parameters.Add(New OleDbParameter("Medication", Medication.ToString))
cmdAddPatient_Medical_History.ExecuteNonQuery()
DataTable_patient_medical_history.AcceptChanges()
conn.Close()
conn.Open()
'Add edited data to the Dental Details table
Dim cmdAddPatient_Dental_Details As New OleDbCommand("Insert into `Dental_Details` (`ID`, `DateOfLastDentalCare`, `HowOftenBrush`, `SnackBtwMeals`, `EatManySweets`, `EatRawVeggies`, `EatFreshFruits`, `H/OInjury`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", conn)
cmdAddPatient_Dental_Details.Parameters.Add(New OleDbParameter("ID", PatientID_ToolStripLabel.Text))
cmdAddPatient_Dental_Details.Parameters.Add(New OleDbParameter("DateOfLastDentalCare", Trim(Format(DOLDC_DateTimePicker.Value, "hh:mm tt"))))
cmdAddPatient_Dental_Details.Parameters.Add(New OleDbParameter("HowOftenBrush", BrushFreq_ComboBox.SelectedText))
cmdAddPatient_Dental_Details.Parameters.Add(New OleDbParameter("SnackBtwMeals", SnackBetweenMeals))
cmdAddPatient_Dental_Details.Parameters.Add(New OleDbParameter("EatManySweets", EatManySweets))
cmdAddPatient_Dental_Details.Parameters.Add(New OleDbParameter("EatRawVeggies", EatRawVegetables))
cmdAddPatient_Dental_Details.Parameters.Add(New OleDbParameter("EatFreshFruits", EatFreshFruits))
cmdAddPatient_Dental_Details.Parameters.Add(New OleDbParameter("H/OInjury", HO_Injury))
cmdAddPatient_Dental_Details.ExecuteNonQuery()
DataTable_patient_dental_history.AcceptChanges()
conn.Close()
conn.Open()
'Add edited data to the Habits table
Dim cmdAddPatient_Habits As New OleDbCommand("Insert into `Habits` (`ID`, `ThumbSucking_Earlier`, `ThumbSucking_Presently`, `NailBiting_Earlier`, `NailBiting_Presently`, `LipBiting_Earlier`, `LipBiting_Presently`, `TongueThrusting_Earlier`, `TongueThrusting_Presently`, `Bruxism_Earlier`, `Bruxism_Presently`, `MouthBreathing_Earlier`, `MouthBreathing_Presently`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", conn)
cmdAddPatient_Habits.Parameters.Add(New OleDbParameter("ID", PatientID_ToolStripLabel.Text))
cmdAddPatient_Habits.Parameters.Add(New OleDbParameter("ThumbSucking_Earlier", TSE))
cmdAddPatient_Habits.Parameters.Add(New OleDbParameter("ThumbSucking_Presently", TSP))
cmdAddPatient_Habits.Parameters.Add(New OleDbParameter("NailBiting_Earlier", NBE))
cmdAddPatient_Habits.Parameters.Add(New OleDbParameter("NailBiting_Presently", NBP))
cmdAddPatient_Habits.Parameters.Add(New OleDbParameter("LipBiting_Earlier", LBE))
cmdAddPatient_Habits.Parameters.Add(New OleDbParameter("LipBiting_Presently", LBP))
cmdAddPatient_Habits.Parameters.Add(New OleDbParameter("TongueThrusting_Earlier", TTE))
cmdAddPatient_Habits.Parameters.Add(New OleDbParameter("TongueThrusting_Presently", TTP))
cmdAddPatient_Habits.Parameters.Add(New OleDbParameter("Bruxism_Earlier", BE))
cmdAddPatient_Habits.Parameters.Add(New OleDbParameter("Bruxism_Presently", BP))
cmdAddPatient_Habits.Parameters.Add(New OleDbParameter("MouthBreathing_Earlier", MBE))
cmdAddPatient_Habits.Parameters.Add(New OleDbParameter("MouthBreathing_Presently", MBP))
cmdAddPatient_Habits.ExecuteNonQuery()
DataTable_patient_habits.AcceptChanges()
conn.Close()
conn.Open()
'Add edited data to the Family Dental History table
Dim cmdPatient_Family_Dental_History As New OleDbCommand("Insert into `Family_Dental_History` (`ID`, `Father_Occlusion`, `Mother_Occlusion`, `Sibling_Occlusion`, `Reffered_By`, `Family_Dentist`) VALUES (?, ?, ?, ?, ?, ?)", conn)
cmdPatient_Family_Dental_History.Parameters.Add(New OleDbParameter("ID", PatientID_ToolStripLabel.Text))
cmdPatient_Family_Dental_History.Parameters.Add(New OleDbParameter("Father_Occlusion", FOcc_TextBox.Text))
cmdPatient_Family_Dental_History.Parameters.Add(New OleDbParameter("Mother_Occlusion", MOcc_TextBox))
cmdPatient_Family_Dental_History.Parameters.Add(New OleDbParameter("Sibling_Occlusion", SOcc_TextBox.Text))
cmdPatient_Family_Dental_History.Parameters.Add(New OleDbParameter("Reffered_By", ReffBy_TextBox.Text))
cmdPatient_Family_Dental_History.Parameters.Add(New OleDbParameter("Family_Dentist", FamilyDentist_TextBox))
cmdPatient_Family_Dental_History.ExecuteNonQuery()
DataTable_patient_family_dental_history.AcceptChanges()
conn.Close()
conn.Open()
'Add edited data to the Final Diagnosis table
Dim cmdPatient_Diagnosis As New OleDbCommand("Insert into `Final_Diagnosis` (`ID`, `Final_Diagnosis`, `Treatment_Plan`, `Photographs`, `Diet_Counselling`, `Brushing`,`Letter_After_Insertion`) VALUES (?, ?, ?, ?, ?, ?, ?)", conn)
cmdPatient_Diagnosis.Parameters.Add(New OleDbParameter("ID", PatientID_ToolStripLabel.Text))
cmdPatient_Diagnosis.Parameters.Add(New OleDbParameter("Final_Diagnosis", FinalDiag_TextBox.Text))
cmdPatient_Diagnosis.Parameters.Add(New OleDbParameter("Notes", Notes_TextBox.Text))
cmdPatient_Diagnosis.Parameters.Add(New OleDbParameter("Treatment_Plan", TreatmentPlan_TextBox))
cmdPatient_Diagnosis.Parameters.Add(New OleDbParameter("Photographs", Photographs))
cmdPatient_Diagnosis.Parameters.Add(New OleDbParameter("Diet_Counselling", DietCounselling))
cmdPatient_Diagnosis.Parameters.Add(New OleDbParameter("Brushing", Brushing))
cmdPatient_Diagnosis.Parameters.Add(New OleDbParameter("Letter_After_Insertion", LetterAfterInsertion))
cmdPatient_Diagnosis.ExecuteNonQuery()
DataTable_patient_diagnosis.AcceptChanges()
conn.Close()
conn.Open()
'Add edited data to the Ammount Due table
Dim cmdPatient_Ammount_Due As New OleDbCommand("Insert into `Ammount_Due` (`ID`, `Total_Ammount`) VALUES (?, ?)", conn)
cmdPatient_Ammount_Due.Parameters.Add(New OleDbParameter("ID", PatientID_ToolStripLabel.Text))
cmdPatient_Ammount_Due.Parameters.Add(New OleDbParameter("Total_Ammount", Total_Ammount_Due_TextBox.Text))
cmdPatient_Ammount_Due.ExecuteNonQuery()
DataTable_patient_total_ammount_due.AcceptChanges()
conn.Close()
'Display the error to the user, if any
Catch ex As Exception
MsgBox("Error!" + " " + ex.Message, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly)
End Try
Dim success_patients As Boolean
Dim success_patients_details As Boolean
Dim success_patient_contact_details As Boolean
Dim success_patient_medical_history As Boolean
Dim success_patient_dental_history As Boolean
Dim success_patient_patient_habits As Boolean
Dim success_patient_family_dental_history As Boolean
Dim success_patient_diagnosis As Boolean
Dim success_patient_total_ammount_due As Boolean
Dim operation_success As Boolean
'establish command object
comm = New OleDbCommand("Select * from Patients", conn)
'establish data adapter/data table
adapter_patients = New OleDbDataAdapter()
adapter_patients.SelectCommand = comm
adapter_patients.Fill(DataTable_patients)
Dim dbdr As OleDbDataReader = comm.ExecuteReader()
If dbdr.HasRows Then success_patients = True
'establish command object
comm = New OleDbCommand("Select * from Patient_Details", conn)
'establish data adapter/data table
adapter_patient_details = New OleDbDataAdapter()
adapter_patient_details.SelectCommand = comm
adapter_patient_details.Fill(DataTable_patient_details)
comm.ExecuteReader()
If dbdr.HasRows Then success_patients_details = True
'establish command object
comm = New OleDbCommand("Select * from Patient_Contact_Details", conn)
'establish data adapter/data table
adapter_patient_contact_details = New OleDbDataAdapter()
adapter_patient_contact_details.SelectCommand = comm
adapter_patient_contact_details.Fill(DataTable_patient_contact_details)
comm.ExecuteReader()
If dbdr.HasRows Then success_patient_contact_details = True
'establish command object
comm = New OleDbCommand("Select * from Medical_History", conn)
'establish data adapter/data table
adapter_patient_medical_history = New OleDbDataAdapter()
adapter_patient_medical_history.SelectCommand = comm
adapter_patient_medical_history.Fill(DataTable_patient_medical_history)
comm.ExecuteReader()
If dbdr.HasRows Then success_patient_medical_history = True
'establish command object
comm = New OleDbCommand("Select * from Dental_Details", conn)
'establish data adapter/data table
adapter_patient_dental_history = New OleDbDataAdapter()
adapter_patient_dental_history.SelectCommand = comm
adapter_patient_dental_history.Fill(DataTable_patient_dental_history)
comm.ExecuteReader()
If dbdr.HasRows Then success_patient_dental_history = True
'establish command object
comm = New OleDbCommand("Select * from Habits", conn)
'establish data adapter/data table
adapter_patient_habits = New OleDbDataAdapter()
adapter_patient_habits.SelectCommand = comm
adapter_patient_habits.Fill(DataTable_patient_habits)
comm.ExecuteReader()
If dbdr.HasRows Then success_patient_patient_habits = True
'establish command object
comm = New OleDbCommand("Select * from Family_Dental_History", conn)
'establish data adapter/data table
adapter_patient_family_dental_history = New OleDbDataAdapter()
adapter_patient_family_dental_history.SelectCommand = comm
adapter_patient_family_dental_history.Fill(DataTable_patient_family_dental_history)
comm.ExecuteReader()
If dbdr.HasRows Then success_patient_family_dental_history = True
'establish command object
comm = New OleDbCommand("Select * from Final_Diagnosis", conn)
'establish data adapter/data table
adapter_patient_diagnosis = New OleDbDataAdapter()
adapter_patient_diagnosis.SelectCommand = comm
adapter_patient_diagnosis.Fill(DataTable_patient_diagnosis)
comm.ExecuteReader()
If dbdr.HasRows Then success_patient_diagnosis = True
'establish command object
comm = New OleDbCommand("Select * from Final_Diagnosis", conn)
'establish data adapter/data table
adapter_patient_total_ammount_due = New OleDbDataAdapter()
adapter_patient_total_ammount_due.SelectCommand = comm
adapter_patient_total_ammount_due.Fill(DataTable_patient_total_ammount_due)
comm.ExecuteReader()
If dbdr.HasRows Then success_patient_total_ammount_due = True
'If the data exists in all the datatables then the operation is a success
If success_patient_contact_details = True And _
success_patient_dental_history = True And _
success_patient_diagnosis = True And _
success_patient_family_dental_history = True And _
success_patient_medical_history = True And _
success_patient_patient_habits = True And _
success_patients = True And _
success_patients_details = True And _
success_patient_total_ammount_due = True Then
operation_success = True
End If
If operation_success = True Then
MsgBox("Record added successfully!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly)
ElseIf operation_success = False Then
MsgBox("Error: Record not added", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly)
End If
Add_Locked = False
conn.Close()
conn.Dispose()
推荐答案
首先,帮自己一个忙.如果您有这样的代码块
First, do yourself a favor. If you have code blocks like this
If UMCYes_RadioButton.Checked = True Then
Under_Medical_Care = True
ElseIf UMCNo_RadioButton.Checked = True Then
Under_Medical_Care = False
End If
它告诉我只能有两个状态(没有第三个状态,因为它需要一个Else块).然后,复选框是单选按钮的另一种(也许是更好的)方法.然后,您可以访问
it shows me that there can be only two states (there is no 3rd as it required an Else block). Then Checkboxes are another (maybe a better) way than RadioButtons. You can then just access
UMC.Checked
UMC.Checked
或者,如果确实需要分配给变量,则为
or, if it's really required to assign to a variable, it would be
Under_Medical_Care = UMC.Checked
所以,五行变成了一行.
So, five lines became one.
然后,顺序
conn.Close()
conn.Open()
即使它不花很多钱,也没有必要.
is also not necessary even if it doen't cost a lot.
我还建议仅创建一次OleDbCommand对象.每次执行它们时,只需更改参数值即可.
I also suggest to create the OleDbCommand objects only once. Every time you execute them, you will only have to change the parameter values.
最重要:您没有告诉我们发生异常的位置.可能是这些行之一:
Most important: You didn't tell us where the exception occurs. Probably it is in one of these lines:
cmdAddPatient_Details.Parameters.Add(New OleDbParameter("DOB", Trim(Format(Age_DateTimePicker.Value, "hh:mm tt"))))
数据库中的数据类型必须与Parameter值的数据类型匹配.在这种情况下,如果数据库中的类型为日期/时间,则参数值也必须为日期时间.在这种情况下,它是一个字符串,因此会发生异常.
The data type in the database must match the data type of the Parameter value. In this case, if the type in the DB is Date/Time, the parameter value must also be of DateTime. In this case, it is a String, hence an exception will occur.
使用参数的优点之一是您可以 不必格式化值.在这种情况下,您可以编写
One of the advantages of using Parameters is that you do not have to format the values. In this case, you could just write
cmdAddPatient_Details.Parameters.Add(New OleDbParameter("DOB", Age_DateTimePicker.Value))
请注意,还有
cmdAddPatient_Details.Parameters.AddWithValue("DOB", Age_DateTimePicker.Value)
可以进一步简化代码.
which can simplify the code additionally.
编辑:我只是看到部分地您使用了复选框,所以您可以缩短它
EDIT: I just see, partially you've used checkboxes, so you can shorten this
如果TTE_CheckBox.Checked = True,那么
TTE =真实
ElseIf TTE_CheckBox.Checked = True然后
TTE =假
如果结束
If TTE_CheckBox.Checked = True Then
TTE = True
ElseIf TTE_CheckBox.Checked = True Then
TTE = False
End If
到
TTE = TTE_CheckBox.Checked
TTE = TTE_CheckBox.Checked
您似乎也正在使用DataTables.您是否有一个特殊的原因来明确执行命令,而不是使用为您完成所有同步的DataAdapter?我看不到总体情况,但这可能是一个选择.
You also seem to be using DataTables. Is there a special reason you explicitly execute command's instead of using a DataAdapter that does all the synchronization for you? I don't see the overall picture, but this might be an option.
EDIT#2 :各行
comm.ExecuteReader()
comm.ExecuteReader()
没有道理. ExecuteReader是一个返回阅读器的函数.如果忽略返回值,则可以完全删除前几行.但是,此后,您访问"dbdr.HasRows";也许您实际上想参考您所拥有的读者 在之前的行中被忽略-我不知道.
do not make sense. ExecuteReader is a function returning a reader. If you ignore the return value, you could completely delete the preceding lines. However, afterwards you access "dbdr.HasRows"; maybe you actually want to refer to the reader you've ignored in the line before - I don't know.
我不了解很多事情,所以我只能猜测是对的.例如,您执行从患者中选择*".只看表中是否有任何行.如果不需要所有行,则将其替换为从患者中选择Count(*)".
并改为执行OleDbCommand的ExecuteScalar函数-但我不知道检索该数字是否完全有意义.
There are many things I don't understand, so I can only guess what's right. For example, you execute "Select * from Patients" only to see if there is any row in the table. If you don't need all rows, replace it by "select Count(*) from patients"
and execute the OleDbCommand's ExecuteScalar function instead - but I don't know if retrieving that number makes sense at all.
使用后,还必须调用每个DataReaders Close方法.
You must also call each DataReaders Close method after usage.
这篇关于critera表达式中的数据类型不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!