-
Re: SelectedIndexChanged
Hallo,
I have a combobox called CmbPaymethod which is built up of 2 fields either BACS or Cheque. Therefore when a user selects either on the form the respective oracle number in textbox called TxtOracleNo changes to reflect that payment method. For example for a specific practice the payment method for BACS = 32 and Cheque = 40. Note: Each practice have unique oracle number.
Now, if a payment method is not available in the database there wont be an oracle number for it. I have this code below which changes when ever BACS /Cheque is selected by reading the Oracle_no from the table.
Dim cmd As New SqlCommand
Dim conn As SqlConnection = GetDbConnection()
Try
Dim Oracle_num As New System.Data.SqlClient.SqlCommand(("SELECT Oracle_no FROM gprdsql.TblOracleNos WHERE Prac_no='" & _
Me.TxtPracNo.Text & "' and Prac_eid = '" & _
Me.TxtPracEid.Text & "' and Pay_method = '" & _
Me.CmbPayMethod.Text & "' "), conn)
Using reader As System.Data.SqlClient.SqlDataReader = Oracle_num.ExecuteReader()
While reader.Read()
Dim Oracle_no As String = FixNull(reader.GetValue(0))
TxtOracleNo.Text = Oracle_no
TextBox6.Text = Oracle_no
End While
End Using
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "GCPM")
End Try
What I want to do now is, when Payment method is selected (i.e., either BACS or Cheque and the oracle number is not available and hence TxtOracleNo.Text doesn't change a msgbox pops saying,
MsgBox("No Oracle number for this Payment Method. Enter Oracle number.", MsgBoxStyle.Information, "GCPM")
Thanks for your help
-
Re: SelectedIndexChanged
Why don't you load the combobox with all available payment method option ONCE, and set its dropdown style to dropdownlist. That way:
1. You don't have to visit the DB for every selection change made by the user.
2. The users can only choose what is available from the list and they cannot put in an invalid payment method.
-
Re: SelectedIndexChanged
The application has been developed by another developer, I just need to add this functionality.
Secondly, if an oracle_no is not available I would like the user to be prompted to enter the oracle_no to be stored to the table.
Thanks for your suggestion though
-
Re: SelectedIndexChanged