嗨,大家好,如果数据库中存在相同的Id,我会尝试发送消息。但If语句不适用于OleDb.OleDbDataAdapte 如何解决这个问题并使If语句有效?
If Da1 = New OleDb.OleDbDataAdapter("select * from Payments where BookingID = " &
CInt(txtBookingID.Text) & "", Con1) Then
MessageBox.Show("This Bill for this Booking is existed in the system.
You Can not add it again.", "Authentication Failure", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
else
new_rec("BookingID") = txtBookingID.Text
new_rec("DateAndTime") = lblDateAndTime.Text
Dt1.Rows.Add(new_rec)
Da1.Update(Dt1)
MessageBox.Show("Booking ID " + " *" + txtBookingID.Text + "* " +
"has been Saved to The System. Press * OK * to Go Back")
end if
答案 0 :(得分:0)
试试这个
Da1 = New OleDb.OleDbDataAdapter("select * from Payments", Con1)
da1.Fill(dt1)
If dt1 is nothing orelse dt1.select("boolingid=" & txtBookingID.Text).count > 0 Then
MessageBox.Show("This Bill for this Booking is existed in the system. You
Can not add it again.", "Authentication Failure", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
else
new_rec("BookingID") = txtBookingID.Text
new_rec("DateAndTime") = lblDateAndTime.Text
Dt1.Rows.Add(new_rec)
Da1.Update(Dt1)
MessageBox.Show("Booking ID " + " *" + txtBookingID.Text + "* " +
"has been Saved to The System. Press * OK * to Go Back")
end if