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.SqlClient;
- namespace login
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- string cs = @"server=162.253.224.12;user id=meisterc;database=meisterc_mybb598;persistsecurityinfo=True;";
- private void button2_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (textBox1.Text == "" || textBox2.Text == "")
- {
- MessageBox.Show("Please provide Username and Password");
- return;
- }
- try
- {
- //Create SqlConnection
- SqlConnection con = new SqlConnection(cs);
- SqlCommand cmd = new SqlCommand("Select * from tbl_Login where UserName=@username and Password=@password", con);
- cmd.Parameters.AddWithValue("@username", textBox1.Text);
- cmd.Parameters.AddWithValue("@password", textBox2.Text);
- con.Open();
- SqlDataAdapter adapt = new SqlDataAdapter(cmd);
- DataSet ds = new DataSet();
- adapt.Fill(ds);
- con.Close();
- int count = ds.Tables[0].Rows.Count;
- //If count is equal to 1, than show frmMain form
- if (count == 1)
- {
- MessageBox.Show("Login Successful!");
- this.Hide();
- Main mm = new login.Main();
- mm.Show();
- }
- else
- {
- MessageBox.Show("Login Failed!");
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement