Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
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 SignUp : System.Web.UI.Page
{
    DateTime dt;
    SqlCommand cmd;
    SqlConnection cn;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        cn = new SqlConnection(ConfigurationManager.AppSettings["cn"]);
        cn.Open();===>this was error it was giving
        
    }
    protected void btnRegister_Click(object sender, EventArgs e)
    {
        SqlDataReader dr;


    

    
        cmd = new SqlCommand("Select * From Registration where uname = '" + txt_uname.Text + "' or email = '" + txt_email.Text + "'", cn);
        dr = cmd.ExecuteReader();
        if (dr.Read())
        {
            lblerr.Text = "User Already Exists Try Again.";
        }
        else
        {
            dr.Close();
            string qu = "INSERT INTO Registration values ('" + txt_uname.Text + "','" + txt_pass.Text + "','" + txt_fname.Text + "','" + txt_mname.Text + "','" + txt_lname.Text + "','" + txt_address.Text + "','" + txt_email.Text + "','" + drp_gender.SelectedItem.Value + "','" + drp_country.SelectedItem.Value + "','" + txt_city.Text + "'," + txt_mobile.Text + ",'" + drp_sque.SelectedItem.Text + "','" + txt_ans.Text + "','')";
            cmd = new SqlCommand(qu);
            cmd.Connection = cn;
            cmd.ExecuteNonQuery();
            lblerr.Text = "User is Registered.";
            Response.Redirect("Login.aspx");
        }
    }
}
Posted
Updated 6-Mar-12 22:51pm
v2
Comments
sankyn1 7-Mar-12 4:51am    
and it was giving error that the connection string property is not initilised
sankyn1 7-Mar-12 5:12am    
xml version="1.0"?>

Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\vx.x\Config
-->
configuration
appSettings
connectionStrings
add name="itplusConnectionString" connectionString="Data Source=localhost\sqlexpress;Initial Catalog=itplus;Integrated Security=True"
providerName="System.Data.SqlClient"
connectionStrings
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">

<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows">
<!--
The <customerrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.

<customerrors mode="RemoteOnly" defaultredirect="GenericErrorPage.htm">
<error statuscode="403" redirect="NoAccess.htm">
<error statuscode="404" redirect="FileNotFound.htm">

-->


1. Check your web.config for the connection string.
2. If connection string is present check it points to right DB.
3. Check if the security and authentication parameters are passes correctly.


My suggestion browse the database from visual studio. get the connection string from the properties window. use this connection string in web.config.
 
Share this answer
 
Comments
sankyn1 7-Mar-12 4:55am    
ok i will try 1 minute
sankyn1 7-Mar-12 4:58am    
how i can do that
Try replacing

C#
cn = new SqlConnection(ConfigurationManager.AppSettings["cn"]);

with
C#
cn = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString);
 
Share this answer
 
Comments
Dylan Morley 7-Mar-12 4:57am    
Yep - most likely
sankyn1 7-Mar-12 5:01am    
here cn has to be my table or some thing else
OriginalGriff 7-Mar-12 5:21am    
The name of the connection string you stored in the web.config
sankyn1 7-Mar-12 5:07am    
it was giving the error null exception was un handled by user code
Check that you are able to connect to the database i.e. you have the appropriate permissions to the database and that your connection string is correct.
 
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