Click here to Skip to main content
15,912,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 registration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegConnectionString"].ConnectionString);
con.Open();
string cmdStr="Select count(*) from Registration where Username ='"+TextBoxUN.Text+"'";
SqlCommand UserExit=new SqlCommand(cmdStr,con);
int temp = Convert.ToInt32(UserExit.ExecuteScalar().ToString());
con.Close();
if(temp==1)
{
Response.Write("Username already exist...!!!
please choose another Username");
}

}

protected void Submit_Click1(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegConnectionString"].ConnectionString);
con.Open();
string inCmd="Insert into Registration (UserName, Password, EmailAddress, Country) Values (@UserName,@Password,@EmailAddress,@Country)";
SqlCommand insertUser = new SqlCommand(inCmd,con);
insertUser.Parameters.AddWithValue("@UserName",TextBoxUN.Text);
insertUser.Parameters.AddWithValue("@Password",TextBoxPass.Text);
insertUser.Parameters.AddWithValue("@EmailAddress",TextBoxEA.Text);
insertUser.Parameters.AddWithValue("@FullName",TextBoxFN.Text);
insertUser.Parameters.AddWithValue("@Country",DropDownListCountry.SelectedItem.ToString());


try
{
insertUser.ExecuteNonQuery();
con.Close();
Response.Redirect("login.aspx");
}
catch(Exception er)
{

Response.Write("something is bad happened");
}
finally
{
//any special thing you want add
}



}
}
Posted

check i web.config do you have RegConnectionString connection string or it is typed correctly.
and also check is your connection string right for connection.
 
Share this answer
 
Comments
Sandeep Mewara 16-Feb-13 3:14am    
My 5 - Right suggestion.
Member 8825505 16-Feb-13 11:23am    
ok
SqlConnection(ConfigurationManager.ConnectionStrings["RegConnectionString"].ConnectionString);




here in this line i have error about nullrefrenceexception.........
 
Share this answer
 
Comments
Member 8825505 16-Feb-13 11:22am    
check connection string of your project.check authentication is proper or not.post your connection-string.

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