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

Thank You

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.