5
Answers

Not Comparing the values from the database

parimal patel

parimal patel

15y
3.2k
1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace AirLine
{
    public partial class _Default : System.Web.UI.Page
    {

        
        
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {
            
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            generatedata();
           
        }
        
        private void generatedata()
        {

            string username, password;
            username = TextBox1.Text.Trim();
            password = TextBox2.Text.Trim();

            SqlConnection conn;
            conn = new SqlConnection("server=HOME-1E79531B32;database=AirLineReservation;trusted_connection=yes");
            conn.Open();
            SqlCommand cmd = new SqlCommand("SELECT * FROM Logon", conn);
            //SelectCommand = "SELECT [UserName], [Password] FROM [Logon] WHERE [UserName] = ";
            SqlDataAdapter dad = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
//            int das;

            dad.Fill(ds);
            SqlDataReader myreader = null;
            try
            {
                myreader = cmd.ExecuteReader();
                while(myreader.Read())
                {
                    string username1 = (myreader["username"].ToString());
                    string password1 = (myreader["password"].ToString());

                    if ((username == username1) && (password == password1))
                    {
                        Response.Redirect("SuccessfulLogin.aspx");
                    }
                    else
                    {
                        Label4.Text = "Check UserName and Password";
                    }
                }
                conn.Close();
            }
            catch(Exception oe)
            {
                Label4.Text = "Idiot";
            }
            
            //DataTable dr = ds.Tables[0];
            //for (int i = 0; i < dr.Rows.Count; i++)
            //{
            //    string username1 = dr.Rows[i][0].ToString();
            //    string password1 = dr.Rows[i][1].ToString();
            //    //int stat = Convert.ToInt32(dr.Rows[i]["status"]);
            //   if ((username1 == username) && (password1 == password))
            //        {
            //            Server.Transfer("SuccessfullLogin.aspx");
            //            break;
            //        }
            //        else
            //        {
            //            Server.Transfer("Register.aspx");
            //        }
                
               
            //}

                
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("Register.aspx");
        }
    }
}

Answers (5)