Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
its showing error in line number 26..
C#
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

public partial class home : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegconnectionString"].ConnectionString);
        con.Open();
        string cmdStr = "Select Count(*) from Registration where UserName='" + TextBox1.Text + "'";
        SqlCommand Checkuser = new SqlCommand(cmdStr, con);
        int temp = Convert.ToInt32(Checkuser.ExecuteScalar().ToString());
        if (temp == 1)
        {
            string cmdstr2 = "Select Password from Registration where UserName='" + TextBox1 + "'";
            SqlCommand pass = new SqlCommand(cmdstr2, con);
            string password = pass.ExecuteScalar().ToString();
            con.Close();
            if (password == TextBox2.Text)
            {
                Session["New"] = TextBox1.Text;
                Response.Redirect("gallery.aspx");
            }
            else
            {
                Label1.Visible = true;
                Label1.Text = "Invalid Password...!!!";
            }
        }
        else
        {
            Label1.Visible = true;
            Label1.Text = "Invalid UserName...!!!";
        }
    }
}
Posted
Updated 1-Jun-12 2:44am
v2
Comments
Prasad_Kulkarni 1-Jun-12 8:44am    
what's error Saman??

1 solution

hi.
the result of "pass.ExecuteScalar()" may be a null value.
You can't call ToString() method of a null.

C#
object password = pass.ExecuteScalar();
if (password != null)
{
    //here you can use password
}
 
Share this answer
 

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