You are loading your dataset with all the records in your database table,and then checking the name with the first row. Try something like this:
protected void Register_btn_Click(object sender, EventArgs e)
{
con = new SqlConnection("Data Source=USER-PC;Initial Catalog=myproject;User ID=sa;Password=Password1");
cmd = new SqlCommand("Select * from Registration_table", con);
adt = new SqlDataAdapter();
adt.SelectCommand = cmd;
ds = new DataSet();
adt.Fill(ds, "table");
if (ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (txt_Uname.Text == dr[0].ToString())
{
Label2.Text = "Username already exists";
Panel1.Visible = false;
return;
}
}
else
{
Register();
}
}
}
This is just one approach. You could use linq, or in your query select just the records with name= txt_Uname and count to check if username is already there.