private void login_btn_Click(object sender, EventArgs e) { //SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-BJH69LU\ASHISSQL;Initial Catalog=Stock;Integrated Security=True"); SqlConnection con = MyConnection.GetConnection(); SqlDataAdapter sda = new SqlDataAdapter(@"SELECT * FROM[dbo].[tbl_login] WHERE username = '******' AND password = '******'", con); DataTable dt = new DataTable(); sda.Fill(dt); //CTRL + KD To align if (dt.Rows.Count == 1) { this.Hide(); StockMain main = new StockMain(); main.Show(); } else { MessageBox.Show("Invalid login details", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); clear_btn_Click(sender, e); } }
public void loadData() { SqlConnection con = MyConnection.GetConnection(); SqlDataAdapter sda = new SqlDataAdapter(@"SELECT * FROM [dbo].[tbl_products]", con); DataTable dt = new DataTable(); sda.Fill(dt); products_tbl.Rows.Clear(); foreach (DataRow item in dt.Rows) { int n = products_tbl.Rows.Add(); products_tbl.Rows[n].Cells[0].Value = item["product_id"].ToString(); products_tbl.Rows[n].Cells[1].Value = item["product_name"].ToString(); if ((bool)item["product_status"]) { products_tbl.Rows[n].Cells[2].Value = "Active"; } else { products_tbl.Rows[n].Cells[2].Value = "Deactive"; } } }