Click here to Skip to main content
16,004,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection
                            (@"Data Source=LEAPTHOUGHT\SQLEXPRESS;Initial Catalog=master;Integrated Security=True");
            SqlDataAdapter sda = new SqlDataAdapter("Select Count(*) from Login where UserName = ''+textBox1.Text + '' and Password= ''+ textBox2.Text +'' ",conn);

            DataTable dt = new DataTable();
            sda.Fill(dt);
            if (dt.Rows[0][0].ToString() == "1")
            {
                this.Hide();
                Form2 form2 = new Form2();
                form2.ShowDialog();
            }
            else
            {
                MessageBox.Show("Please check your login credentials");
            }


        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
Posted

1 solution

Change code to

C#
SqlDataAdapter sda = new SqlDataAdapter("Select Count(*) from Login where UserName = '"+textBox1.Text + "' and Password= '"+ textBox2.Text +"' ",conn);
 
Share this answer
 
Comments
[no name] 23-Apr-14 10:01am    
Working fine!! Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900