i have 2 pages login and signup. and I want to check whether the user is already exist or not.
What I have tried:
public partial class Login : System.Web.UI.Page
{
string cs = ConfigurationManager.ConnectionStrings["NDBCS"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
LoadTrack();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(cs);
con.Open();
SqlCommand cmd = new SqlCommand("Insert into tbl_User (Firstname, Lastname, Track_id, Username, Email, Password) values (@firstname, @lastname, @track, @username, @email, @password)", con);
cmd.Parameters.AddWithValue("@firstname", txtbox_FN.Text);
cmd.Parameters.AddWithValue("@lastname", txtbox_LN.Text);
cmd.Parameters.AddWithValue("@track", ddl_Track.SelectedValue);
cmd.Parameters.AddWithValue("@username", txtbox_UN.Text);
cmd.Parameters.AddWithValue("@email", txtbox_Email.Text);
cmd.Parameters.AddWithValue("@password", txtbox_PW.Text);
cmd.ExecuteNonQuery();
con.Close();
}
private void LoadTrack()
{
try
{
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("select * from tbl_Track", con);
con.Open();
DataTable table = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(table);
ddl_Track.DataSource = table;
ddl_Track.DataValueField = "Track_id";
ddl_Track.DataTextField = "Track_code";
ddl_Track.DataBind();
ddl_Track.Items.Insert(0, new ListItem("--Select Category--", "0"));
}
}
catch (Exception ex)
{
Label1.ForeColor = System.Drawing.Color.Red;
Label1.Text = "Something went wrong!." + ex.Message + "";
Label1.Visible = false;
}
}