1

I'm working with SQL Server 2008R2 and VS 2010

I kept getting this error when I browse I tried opening every page but the same error pops up. Please explain briefly and in simple word what should I do I'm new to this.

[NullReferenceException: Object reference not set to an instance of an object.]

MyProject.login1.ImageButton3_Click(Object sender, ImageClickEventArgs e) in C:\Users\prakash\Desktop\MyProject R2\MyProject R2\MyProject\login1.aspx.cs:26 System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +115 System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +124 System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

Source Code

protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
    {
        int flag = 0;
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["shopingConnectionString1"].ConnectionString);
        string s = "select * from login";
        SqlCommand com = new SqlCommand(s, con);
        con.Open();
        if (con.State == ConnectionState.Open)
        {
            SqlDataReader dtr;
            dtr = com.ExecuteReader();
            while (dtr.Read())
            {
                if (dtr[0].ToString().Equals(TextBox1.Text) && dtr[1].ToString().Equals(TextBox2.Text))
                {


                    Response.Cookies["uname"].Value = TextBox1.Text;
                    Response.Cookies["pwd"].Value = TextBox2.Text;
                    Response.Cookies["role"].Value = dtr[2].ToString();
                    FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);

                }
                else
                {
                    Label1.Text = "your credential are incorrect";
                }
Bohemia
  • 67
  • 4

0 Answers0