0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

namespace Discussion
{
    public partial class Reg : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Submit_Click(object sender, EventArgs e)
        {
            string Sname = TextBox4.Text;
            string Username = txtUse.Text;
            string Psw = Pass.Text;
            string Gender = rdoGender.Text;
            string Cpsw = Cpass.Text;
            string Email = email.Text;

            SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Chat.mdf;Integrated Security=True;User Instance=True;User Instance=True");
            con.Open();

            SqlCommand cmd = new SqlCommand("Select * from Log ", con);
            SqlDataReader dr = null;
            dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                if (Username == dr[2].ToString())
                {
                    Response.Write("username exists");

                }
                else
                {
                    SqlConnection con1 = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Chat.mdf;Integrated Security=True;User Instance=True;User Instance=True");
                    con1.Open();

                    SqlCommand cmd1 = new SqlCommand("Insert into Log values('" + Sname + "','" + Gender + "','" + Username + "','" + Psw + "','" + Email + "' )", con1);

                    cmd1.ExecuteNonQuery();
                    Response.Redirect("Menu.aspx");
                }
                }
            }




    }
}

how do i check for the existing username, and display a message registration failed

2
Contributors
2
Replies
13
Views
4 Years
Discussion Span
Last Post by Neethaa
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.