I have two comboboxes, a messagebox and a Send button. When the app startups and I click on the Send button with the comboboxes and messagebox empty, a pop-up box comes up and says "Select a client" After doing this, I go back to the database and see that it has added a new record to that table, even though I didn't put in any data after clicking on the "Send" button. Same applies for when one of the three controls I have has data in it, but the other two don't, and the program asks me to enter that data before it succeeds. But it still adds the record despite having those If Statements. What am I doing wrong?
My code:
Using con As New SqlConnection(ConfigurationManager.ConnectionStrings("conStr").ConnectionString) con.Open() Using cmd As New SqlCommand cmd.Connection = con cmd.CommandText = "insert into tblMyTable(Client, UserName, Message) values('" & cboClient.Text & "', '" & cboUser.Text & "', '" & rtfMessage.Text & "')" cmd.ExecuteNonQuery() End Using If cboClient.Text = "" Then MsgBox("Select a client") ElseIf cboUser.Text = "" Then MsgBox("Select a user") ElseIf rtfMessage.Text = "" Then MsgBox("Enter a message") Else MsgBox("Message Sent") End If con.Close() End Using