Advertisement
Guest User

Add Command

a guest
Apr 28th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. If btnAdd.Text = "&Add" Then
  2. enable(btnAdd, True)
  3. btnAdd.Text = "&Save"
  4. btnAdd.Image = My.Resources.save
  5. btnExit.Image = My.Resources.cancel
  6. Else
  7. 'SAVE CODE
  8. setConnection()
  9. Try
  10. command = New MySqlCommand
  11. dt = New DataTable
  12. adapter = New MySqlDataAdapter
  13.  
  14. If (conn.State = ConnectionState.Closed) Then
  15. setConnection()
  16. End If
  17.  
  18. 'search for wildcard in the name column
  19. command = New MySqlCommand("insert into " & db_accounting & " (acc_stud,acc_amt,acc_type,acc_rem,acc_discount) values(@id,@amt,@type,@rem,@disc)", conn)
  20. command.Parameters.AddWithValue("@id", lstStudID.Items(lstStud.SelectedIndex))
  21. command.Parameters.AddWithValue("@type", cboD_type.Text)
  22. command.Parameters.AddWithValue("@rem", txtD_rem.Text)
  23.  
  24. If txtD_discount.Text = "" Then
  25. command.Parameters.AddWithValue("@amt", txtD_amt.Text)
  26. command.Parameters.AddWithValue("@disc", "")
  27. Else
  28. command.Parameters.AddWithValue("@amt", lblD_discount.Text)
  29. command.Parameters.AddWithValue("@disc", txtD_discount.Text & "::" & txtD_amt.Text)
  30. End If
  31.  
  32. adapter.SelectCommand = command
  33.  
  34. reader = command.ExecuteReader
  35.  
  36. disable()
  37.  
  38. Catch ex As MySqlException
  39. MessageBox.Show("Error: " & ex.Message)
  40. Finally
  41. reader.Close()
  42. conn.Close()
  43. lstStud_SelectedIndexChanged(sender, e)
  44. End Try
  45. End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement