Guest User

Untitled

a guest
Jan 23rd, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. namespace Phonebooks
  2. {
  3. public partial class _Default : Page
  4. {
  5. MySqlConnection connection = new MySqlConnection("datasource=localhost;port=3306;username=root;password=1234");
  6. public _Default()
  7. {
  8. InitializeComponent();
  9. }
  10.  
  11. private void BTN_INSERT_Click(object sender, EventArgs e)
  12. {
  13. string insertQuery = "INSERT INTO contacts(name,position,h/pno,company's name,address,post code,state,country,tel,did,fax,email) VALUES('" + txtname.Text + "','" + txtposition.Text + "'," + txthpno.Text + "','"+txtcompanyname.Text+"','"+txtadress+"','"+txtpostcode.Text+"','"+txtstate.Text+"','"+txtcountry.Text+"','"+txttel.Text+"','"+txtdirect.Text+"','"+txtfax.Text+"',"+txtemail.Text+")";
  14. connection.Open();
  15. MySqlCommand command = new MySqlCommand(insertQuery, connection);
  16.  
  17. try
  18. {
  19. if (command.ExecuteNonQuery() == 1)
  20. {
  21. MessageBox.Show("Data Inserted");
  22. }
  23. else
  24. {
  25. MessageBox.Show("Data Not Inserted");
  26. }
  27. }
  28. catch (Exception ex)
  29. {
  30. MessageBox.Show(ex.Message);
  31. }
  32.  
  33. connection.Close();
  34.  
  35. }
  36. }
  37. }
Add Comment
Please, Sign In to add comment