0
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;



public partial class userreg : System.Web.UI.Page
{
    SqlConnection con;

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (chk().ToString() == "1")
        {
            con = new SqlConnection(ConfigurationSettings.AppSettings["con"].ToString());
            SqlCommand reg = new SqlCommand("insert into userreg(email,add,fname,lname,age,gender,country,mob_mod,mob_no)values('" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox10.Text + "','" + RadioButtonList1.SelectedItem.ToString() + "','" + DropDownList4.SelectedItem.ToString() + "','" + DropDownList5.SelectedItem.ToString() + "','" + TextBox9.Text + "')", con);
            SqlCommand log = new SqlCommand("insert into Login(uname,pass,role)values('" + TextBox2.Text + "','" + TextBox3.Text + "','user')", con);
            con.Open();
            reg.ExecuteNonQuery();
            log.ExecuteNonQuery();
            Label2.Text = "Registration Complet";
            con.Close();
        }
        else
        {
            Label1.Text = "User Name Not avilable";
        }

        }

    public string chk()
    {
        string flag;
        con = new SqlConnection(ConfigurationSettings.AppSettings["con"].ToString());
        SqlDataAdapter sda=new SqlDataAdapter("select * from Login where uname='"+ TextBox2.Text +"'",con);
        DataSet ds=new DataSet();
        sda.Fill(ds);
        if(ds.Tables[0].Rows.Count>0)
        {
            flag="0";
        }
        else
        {
            flag="1";
        }
        return flag;

    }

    protected void  LinkButton1_Click(object sender, EventArgs e)
{
        if(chk().ToString()=="1")
        {
         Label1.Text="User name available";

        }
        else
        {
            Label1.Text = "plese use different user name";
        }

}
}

Pls replay this solution

Edited by mike_2000_17: Fixed formatting

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by rohand
0

Hi,

Possibilities of this error from the given code.

1) ConfigurationSettings.AppSettings["con"] may be null
2) Dataset is empty
3) chk() function may return null value - due to error it may return null and casting to string may throw error.

The error is occurring when you are accessing a property/value of NULL object.

Please check and let us know.

Note: Always use Code-tags while posting the source code.

Thank you.

Edited by mike_2000_17: Fixed formatting

0

I am agree with MeSampath. Along with their option, you can also know the proper place from where the error is occuring. On your visual studio IDE, you just need to set Alt + Ctrl + E, it will open up Exception dialog box. Now check the Thrown checkbox for Common Language Runtime exception option.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.