Advertisement
Guest User

Untitled

a guest
Jul 9th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.54 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.SQL;
  10. USING System.DATA.SqlClient;
  11.  
  12. namespace LearnOnline
  13. {
  14.     public partial class Form2 : Form
  15.     {
  16.         public Form2()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         private void btnSubParent_Click(object sender, EventArgs e)
  22.         {
  23.             string myConnection = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Grant\Documents\College Work\FD Computing\Year 2\APD\LearnOnline\LearnOnline\Database1.mdf;Integrated Security=True;User Instance=True";
  24.             SqlConnection conn = NEW SqlConnection(myConnection);
  25.  
  26.             try
  27.             {
  28.                 conn.OPEN();
  29.             }
  30.             catch (Exception)
  31.             {
  32.                 MessageBox.SHOW("Connection Failed");
  33.             }
  34.  
  35.             string username = txtboxPUser.Text;
  36.             string password = txtboxPPword.Text;
  37.             string sqlquery = ("SELECT * FROM Parent WHERE Username = '" + txtboxPUser.Text + "'");
  38.  
  39.             sqlquery = "INSERT INTO [Parent] (Username, Password) VALUES ('" + txtboxPUser.Text + "','" + txtboxPPword.Text + "')";
  40.  
  41.             SqlCommand command = NEW SqlCommand(sqlquery, conn);
  42.             command.Parameters.AddWithValue("Username", username);
  43.             command.Parameters.AddWithValue("Password", password);
  44.             command.Parameters.Clear();
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement