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