Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Data.Sql;
- using System.Data.SqlClient;
- namespace Learn_App_Login
- {
- public partial class Form1 : Form
- {
- //khai bao bien
- private SqlConnection InitCon;
- private SqlCommand cmd;
- public Form1()
- {
- InitializeComponent();
- }
- //ham ket noi database
- public static SqlConnection GetCon()
- {
- string strcon = @"data source=LAPTOP-AFR31CFM.;
- initial catalog ='SaleDB';
- user id='LAPTOP-AFR31CFM\D4RKDR4G0N'; password='Hacker12@#!';
- Integrated Security=true;";
- SqlConnection con = new SqlConnection(strcon);
- return con;
- }
- private void label2_Click(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- SqlConnection connectionToServer = new SqlConnection();
- SqlConnection con = GetCon();
- con.Open();
- string sqlSelect = "select * from account" +
- "Where username ='" + txtUsername.Text + "' and password ='" + txtPassword.Text + " ' ";
- // khoi tao doi tuong command
- cmd = new SqlCommand(sqlSelect,con);
- cmd.CommandType = CommandType.Text;
- //khoi tao doi tuong adapter
- SqlDataAdapter adapter = new SqlDataAdapter(cmd);
- //tao datable chua data
- DataTable dt = new DataTable();
- //su dung adapter do data vao table nay
- adapter.Fill(dt);
- //binding eridview voi table
- dgwAccount.DataSource = dt;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement