i have here separated code for inserting new data, and updating changes in existing data in access using vb.net....when i run the program, both run sucessfully...now, i want to use if statement to combine the code for inserting new and updating changes in the data in one command button 'save'..but when i run the program, the program reads the code for update only, not the saving code..it is encloses in the if statement...
Code for saving new data:
Private Sub menu_save_Click(sender As Object, e As EventArgs) Handles menu_save.Click
access = "Insert into tbl_location(locid, locname, locadd) Values ('" & txt_locid.Text & "', '" & txt_locname.Text & "', '" & txt_locadd.Text & "')"
con.Open()
cmd = New OleDbCommand(access, con)
cmd.ExecuteReader(CommandBehavior.CloseConnection)
MsgBox("Successfully Saved....")
con.Close()
End Sub
Code for updating existing data:
Private Sub menu_update_Click(sender As Object, e As EventArgs) Handles menu_update.Click
access = "UPDATE tbl_location SET [locname] = '" & Me.txt_locname.Text & "', [locadd] ='" & Me.txt_locadd.Text & "' WHERE [locid] = '" & Me.txt_locid.Text & "'"
con.Open()
cmd = New OleDbCommand(access, con)
cmd.ExecuteNonQuery()
MsgBox("Successfully Updated...")
con.Close()
End Sub
When i combine the two, enclosing in an if statement:
Private Sub timer_save_Tick(sender As Object, e As EventArgs) Handles timer_save.Tick
If Not Me.strip_progress.Value = Me.strip_progress.Maximum Then
Me.strip_progress.Increment(5)
Me.strip_progress.Visible = True
Else
If Me.strip_progress.Value = Me.strip_progress.Maximum Then
Me.timer_save.Stop()
Me.strip_progress.Value = 0
If Me.txt_locid.Text & "" = "" Then
access = "Insert into tbl_location(locid, locname, locadd) Values ('" & txt_locid.Text & "', '" & txt_locname.Text & "', '" & txt_locadd.Text & "')"
con.Open()
cmd = New OleDbCommand(access, con)
cmd.ExecuteReader(CommandBehavior.CloseConnection)
MsgBox("Successfully Saved....")
con.Close()
Me.menu_update.Enabled = False
Me.menu_save.Enabled = False
Me.txt_locid.Enabled = False
Me.txt_locname.Enabled = False
Me.txt_locadd.Enabled = False
Me.strip_progress.Visible = False
Else
access = "UPDATE tbl_location SET [locname] = '" & Me.txt_locname.Text & "', [locadd] ='" & Me.txt_locadd.Text & "' WHERE [locid] = '" & Me.txt_locid.Text & "'"
con.Open()
cmd = New OleDbCommand(access, con)
cmd.ExecuteNonQuery()
MsgBox("Successfully Updated...")
con.Close()
Me.menu_update.Enabled = False
Me.menu_save.Enabled = False
Me.menu_new.Enabled = True
Me.menu_edit.Enabled = True
Me.menu_search.Enabled = True
Me.txt_locname.Enabled = False
Me.txt_locadd.Enabled = False
End If
End If
End If
End Sub
Can anyone help me to this problem??thank you in advance...