Advertisement
Guest User

ERROR SQL WITH C#

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