Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11.  
  12. namespace ProductMaintenance
  13. {
  14. public partial class Form1 : Form
  15. {
  16. SqlConnection connection = new SqlConnection("server=localhost;user id=root123;database=test;allowuservariables=True;persistsecurityinfo=True");
  17.  
  18. public Form1()
  19. {
  20. InitializeComponent();
  21. }
  22.  
  23. private void Form1_Load(object sender, EventArgs e)
  24. {
  25.  
  26. }
  27.  
  28. private void button1_Click(object sender, EventArgs e)
  29. {
  30. connection.Open();
  31.  
  32. SqlCommand cmd = connection.CreateCommand();
  33.  
  34. cmd.CommandType = CommandType.Text;
  35.  
  36. cmd.CommandText = "insert into [mytable] (Name,Surname,Address) values (' "+ textBox1.Text + " ', '" + textBox2.Text + " ', ' " + textBox3 + "')";
  37.  
  38. cmd.ExecuteNonQuery();
  39. connection.Close();
  40.  
  41. textBox1.Text = "";
  42. textBox2.Text = "";
  43. textBox3.Text = "";
  44. textBox4.Text = "";
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement