Hello
Dear Friends,
I need some help to check avilidity of the username on Leave event of a textbox in Database SQL Server, but i cann't get.
it code is bellow

private void textBox6_Leave(object sender, EventArgs e)
        {
            cmd = new SqlCommand("SELECT * FROM usertab WHERE username='"+textBox6.text+"'",con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);

            da.Fill(ds);
            int i = ds.Tables[0].Rows.Count;
            if (i > 0)
            {
                label21.Text = "username is already exists";
                ds.Clear();
            }
            else
            {

                label21.Text = "username is available";
            }

        }

con Connetion and DataSet=ds are defined in public section.

SqlConnection con = new SqlConnection("data source=MUHAMMAD\\SQLEXPRESS; database = MMS; integrated security = SSPI");
DataSet ds = new DataSet();

Are you getting g any errors? Or are just getting unexpected results?

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.