Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

Username and UserType Validation in asp.net using mysql

$
0
0

I have two tables in the database:

Login (LID,UName,UPasword,UserType_ID)
UserType(UserType_ID,UserType)

I need to validate username and usertype and create a session variable for UserName(UName).

code

 protected void Button1_Click1(object sender, EventArgs e)
        {
            name = Request.Form["TextBox1"].ToString();
            pwd = Request.Form["TextBox2"].ToString();
            conn.Open();
            MySqlCommand cmd = new MySqlCommand(" select * from login  where UName =  '" + name + "'  and  UPasword =  '" + pwd + "' ");
            cmd.Connection = conn;
           // cmd.Connection = conn;
            MySqlDataReader dr = cmd.ExecuteReader();
            if(dr.HasRows )

           {
               dr.Read();
               Session[" UName"] = dr[1].ToString(); ;
               Session[" UPasword"] = dr[4].ToString();
               Session["UserType_ID"] = dr[0].ToString(); ;
               //Session["prenom"] = dr[2].ToString();
               //Session["telephone"] = dr[3].ToString();


           
            Response.Redirect("View_Reports.aspx");
            }
            
            else
                {
                    Response.Redirect("gallery.aspx");

                }

            dr.Close();
            conn.Close();
              

            
        }

but it shows me error on this line

name = Request.Form["TextBox1"].ToString();

ERROR IS

Object reference not set to an instance of an object.


Viewing all articles
Browse latest Browse all 3509

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>