Rowel Virgo
asked on
IF Condition in VB.net - Please Help
Public Sub WORK1()
'read DID from database
Dim cmd1a As MySqlCommand = conn.CreateCommand()
cmd1a.CommandText = "SELECT (did) FROM eliteprototype.tblewhreceive WHERE DID = '" & TextBox1.Text & "' "
cmd1a.CommandType = CommandType.Text
Dim count1 = cmd1a.ExecuteScalar()
cmd1a.Clone()
Label6.Text = count1
'read Gcode from database
Dim cmd2a As MySqlCommand = conn.CreateCommand()
cmd2a.CommandText = "SELECT (gcode) FROM eliteprototype.tblewhreceive WHERE gcode = '" & TextBox2.Text & "' "
cmd2a.CommandType = CommandType.Text
Dim count2 = cmd2a.ExecuteScalar()
cmd2a.Clone()
Label8.Text = count2
'read Quantity frm database
'read Gcode from database
Dim cmd3a As MySqlCommand = conn.CreateCommand()
cmd3a.CommandText = "SELECT (inventory) FROM eliteprototype.tblewhinventory WHERE gcode = '" & TextBox2.Text & "' "
cmd3a.CommandType = CommandType.Text
Dim count3 = cmd3a.ExecuteScalar()
cmd3a.Clone()
Label7.Text = count3
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox2.Text = "" AndAlso TextBox1.Text = "" Then
MsgBox("Can't proceed with blank data", vbInformation, "System says:")
Else
WORK1()
TextBox1.Text = ""
TextBox1.Select()
TextBox2.Text = ""
TextBox2.Enabled = False
End If
End Sub
Above is my code, I want an If condition that control the Public Sub, example:
If WORK1() is successful then
proceed
Else
msgbox(promt that the WORK1() is not succesful)
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I notice also the clone. First I open the connection and then close.. not clone. Thank you sir. I removed it already,
An explicit Close() is only necessary, as long as you want to reuse the command again in the same scope, aka. the same methods body. When my function exits, the scope is left and .Net automatically closes and clean-ups the command object during garbage collection. Thus here it is not necessary.
Open in new window