Guest User

Untitled

a guest
Jul 22nd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 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.Sql;
  11. using System.Data.SqlClient;
  12. namespace Learn_App_Login
  13. {
  14. public partial class Form1 : Form
  15. {
  16. //khai bao bien
  17. private SqlConnection InitCon;
  18. private SqlCommand cmd;
  19.  
  20. public Form1()
  21. {
  22. InitializeComponent();
  23. }
  24. //ham ket noi database
  25. public static SqlConnection GetCon()
  26. {
  27. string strcon = @"data source=LAPTOP-AFR31CFM.;
  28. initial catalog ='SaleDB';
  29. user id='LAPTOP-AFR31CFMD4RKDR4G0N'; password='Hacker12@#!';
  30. Integrated Security=true;";
  31. SqlConnection con = new SqlConnection(strcon);
  32. return con;
  33. }
  34.  
  35. private void label2_Click(object sender, EventArgs e)
  36. {
  37.  
  38. }
  39.  
  40. private void button1_Click(object sender, EventArgs e)
  41. {
  42. SqlConnection connectionToServer = new SqlConnection();
  43. SqlConnection con = GetCon();
  44. con.Open();
  45. string sqlSelect = "select * from account" +
  46. "Where username ='" + txtUsername.Text + "' and password ='" + txtPassword.Text + " ' ";
  47. // khoi tao doi tuong command
  48. cmd = new SqlCommand(sqlSelect,con);
  49. cmd.CommandType = CommandType.Text;
  50. //khoi tao doi tuong adapter
  51. SqlDataAdapter adapter = new SqlDataAdapter(cmd);
  52. //tao datable chua data
  53. DataTable dt = new DataTable();
  54. //su dung adapter do data vao table nay
  55. adapter.Fill(dt);
  56. //binding eridview voi table
  57. dgwAccount.DataSource = dt;
  58.  
  59.  
  60. }
  61. }
  62. }
Add Comment
Please, Sign In to add comment