Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Phonebooks
- {
- public partial class _Default : Page
- {
- MySqlConnection connection = new MySqlConnection("datasource=localhost;port=3306;username=root;password=1234");
- public _Default()
- {
- InitializeComponent();
- }
- private void BTN_INSERT_Click(object sender, EventArgs e)
- {
- 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+")";
- connection.Open();
- MySqlCommand command = new MySqlCommand(insertQuery, connection);
- try
- {
- if (command.ExecuteNonQuery() == 1)
- {
- MessageBox.Show("Data Inserted");
- }
- else
- {
- MessageBox.Show("Data Not Inserted");
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- connection.Close();
- }
- }
- }
Add Comment
Please, Sign In to add comment