How can I make a textbox check if it contains this value inside the table in the DataBase column when I click the button?
I made this code, but I did not succeed:
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["conString"].ConnectionString);
private void button2_Click(object sender, EventArgs e)
{
try
{
SqlCommand cmd = new SqlCommand($"SELECT * FROM Alunos WHERE Numero ={txtNome.Text.Text}", conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
int j = ds.Tables[0].Rows.Count;
if (j == 0)
{
MessageBox.Show("word" + txtNome.Text + "already exists!");
ds.Clear();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}