SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\Projects\\csharp\\Login1\\App_Data\\Login.mdf;Integrated Security=True;User Instance=True");
SqlCommand cmd;
SqlDataReader dr;
protected void LinkButton1_Click(object sender, EventArgs e)
{
conn.Open();
cmd=new SqlCommand("Select * from LoginTable where User Name='"+TextBox1.Text+"'",conn);
dr=cmd.ExecuteReader(); // <---error here
if(dr.Read())
{
Label1.Text="User name already exist";
this.Label1.ForeColor=Color.Red;
}
else
{
Label1.Text="Name available";
}
}
It shows the following error near dr=cmd.ExecuteReader();:
An expression of non-boolean type specified in a context where a condition is expected, near 'Name'.
Whats happening here
Replace the User Name in where clause with [User Name]
The user name must be specified as [User Name] or UserName so please check column name once
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With