Advertisement
Korsunsky

reg

May 28th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 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.Windows.Forms;
  9. using System.Data.SqlClient;
  10.  
  11. namespace WindowsFormsApplication1
  12. {
  13.     public partial class AuthorizationForm : Form
  14.     {
  15.         public AuthorizationForm()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void Button1_Click(object sender,EventArgs e)
  21.         {
  22.             this.Close();
  23.         }
  24.         ////////////////////////////////
  25.         private void insertData()
  26.         {
  27.             string conStr = "server=localhost;user=root;database=exam1;password=qwerty;";
  28.             using (SqlConnection con = new SqlConnection(conStr))
  29.             {
  30.                 try
  31.                 {
  32.                     string sql = "INSERT INTO Login (user,password) VALUES (@user, @password);";
  33.                     con.Open();
  34.                     SqlCommand cmd = new SqlCommand(sql, con);
  35.                     cmd.Parameters.AddWithValue("@user",textBox1.Text);
  36.                     cmd.Parameters.AddWithValue("@password",textBox2.Text);
  37.                     cmd.ExecuteNonQuery();
  38.                 }
  39.                 catch (Exception ex)
  40.                 {
  41.                     MessageBox.Show(ex.Message);
  42.                 }
  43.             }
  44.         }
  45.         ////////////////////////////////////////
  46.         private void Button2_Click(object sender,EventArgs e)
  47.         {
  48.             insertData();
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement