对象引用未设置为VS 2010中的对象实例

时间:2014-02-06 11:05:35

标签: c# asp.net

我正在使用SQL Server 2008R2和VS 2010

我浏览时遇到此错误我尝试打开每个页面但弹出相同的错误。 请简单解释一下,简单地说一下我应该做什么我是新手。

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

MyProject.login1.ImageButton3_Click(Object sender,ImageClickEventArgs e)位于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

源代码

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";
                }

0 个答案:

没有答案