2 Replies - 596 Views - Last Post: 04 December 2015 - 08:30 AM Rate Topic: -----

#1 cronnah   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-December 15

If is not working while else if works

Posted 03 December 2015 - 04:40 PM

Hi All,

Would like to seek your assistance regarding to IF and elseif statement, what's happening here I have a code below, I want that if I select combobox1 with value of MMPGPB0005 with a following query to be executed will save to its table if true, then if I select combobox1 again with a value of MMPGB00013 will save to its table also but what's happening is my if statement ignores but if I run my code it tells me that data is saved to database but if I checked the table for MMPGPB0005 there is no data saved while my else if is working and if I check my database there is a saved data.
can anyone help me to solve this. before that code is works perfectly but yesterday if not working as before testing.
thank you so much in advance.

 Private Sub ApplyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ApplyToolStripMenuItem.Click
        MysqlConn = New MySqlConnection
        MysqlConn.ConnectionString =
       "server=_______;userid=______;password=_______;database=_______;""
        Dim Reader As MySqlDataReader

        Try
            MysqlConn.Open()
            Dim Query As String

            If ComboBox1.Text = "MMPGPB0005" Then
                Query = "insert into mydb.tbl_jlabay (MMPNumber, TypeofLeave, DaysofLeave, FromDate, ToDate, ReportingTo, Comment) Values ('" & ComboBox2.Text & "','" & ComboBox3.Text & "','" & NumericUpDown1.Text & "','" & DateTimePicker1.Text & "','" & DateTimePicker2.Text & "','" & ComboBox1.Text & "','" & TextBox1.Text & "')"
            ElseIf ComboBox1.Text = "MMPGB00013" Then
                Query = "insert into mydb.tbl_jvergara (MMPNumber, TypeofLeave, DaysofLeave, FromDate, ToDate, ReportingTo, Comment) Values ('" & ComboBox2.Text & "','" & ComboBox3.Text & "','" & NumericUpDown1.Text & "','" & DateTimePicker1.Text & "','" & DateTimePicker2.Text & "','" & ComboBox1.Text & "','" & TextBox1.Text & "')"                com = New MySqlCommand(Query, MysqlConn)                Reader = com.ExecuteReader

            End If

            MsgBox("Successfuly saved!.", vbInformation + vbOKOnly)
            MysqlConn.Close()
        Catch ex As MySqlException
            MessageBox.Show(ex.Message)
        Finally
            MysqlConn.Dispose()
        End Try
    End Sub

Attached image(s)

  • Attached Image

This post has been edited by Atli: 03 December 2015 - 05:12 PM
Reason for edit:: Use [code] tags when posting code.


Is This A Good Question/Topic? 0
  • +

Replies To: If is not working while else if works

#2 andrewsw   User is online

  • Entwickler
  • member icon

Reputation: 6599
  • View blog
  • Posts: 26,895
  • Joined: 12-December 12

Re: If is not working while else if works

Posted 03 December 2015 - 04:58 PM

Please put your code within code tags:

Attached Image

Note that you cannot make code bold within the tags.
Was This Post Helpful? 0
  • +
  • -

#3 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14406
  • View blog
  • Posts: 57,763
  • Joined: 12-June 08

Re: If is not working while else if works

Posted 04 December 2015 - 08:30 AM

Does sql reader sound like something that would do an INSERT or UPDATE? Perhaps a 'sql command' object instead?

Not to mention it doesn't make sense why line 12 happens with no sql object to run the query, but line 14 you dump a new reader in there. That reader will only have scope inside that elseif condition.

http://www.dreaminco...-command-setup/
http://www.dreaminco...-adapter-setup/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1