Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hello sir,
               "I am using window form in Visual Studio."
 
            I had given two labels(username and password) with infornt of that ,there will be a textbox and one Login button.I created a username and password fields in MS SQL ,i had given value for username and password in the fields..ok.and when i execute that ,it will ask to enter the username and password,when i entered it will give a error like "An expression of non-boolean type specified in a context where a condition is expected, near 'Name' ".The error in this line   "SqlDataReader rdr = cmd.ExecuteReader();".Can any one solve this...
 
If solution in the code form ,then it will be helpfull.
 
Thanks & Regards
Pradeep
Posted 8-Mar-12 2:54am
Comments
Pete O'Hanlon at 8-Mar-12 7:57am
   
Come on, throw us a bone. At least let us see what the rest of this bit of code looks like.
d@nish at 8-Mar-12 8:21am
   
They must enable voting on comments as well. This one's worth a five.
Pete O'Hanlon at 8-Mar-12 8:49am
   
Thanks. I quite like it.
ryanb31 at 8-Mar-12 8:29am
   
Show the code of your SQL statement. You have an invalid SQL statement.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try this:
            using (SqlConnection con = new SqlConnection(strConnect))
                {
                con.Open();
                using (SqlCommand com = new SqlCommand("SELECT iD, password FROM myTable WHERE userName=@UN", con))
                    {
                    con.Parameters.AddWithValue("@UN", userNameTextBox.Text);
                    using (SqlDataReader reader = com.ExecuteReader())
                        {
                        if (reader.Read())
                            {
                            int id = (int) reader["iD"];
                            byte[] pw = (byte[]) reader["password"];
                            ...
                            }
                        }
                    }
                }
You can then check your password matches and log him in if it does.
BTW: Don't store your password in text format - it is a real security hole. Instead, use a Hashing function. Password Storage: How to do it.[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Check your SQL statements. There is something wrong with if statement or a where clause in it.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

paste your code here...we will try to solve your problem....
  Permalink  
Comments
Pradeep CBZ at 9-Mar-12 1:29am
   
hello sir,
This is the code ,but it is giving error in this line: "SqlDataReader rdr = cmd.ExecuteReader();" and the error is: "An expression of non-boolean type specified in a context where a condition is expected, near 'Name'."
 
My code is :
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=CBP\\SQLEXPRESS;Initial Catalog=ECG;Integrated Security=True;Pooling=False";
//con.ConnectionString = "Data Source=CBP\\SQLEXPRESS;Initial Catalog=hms;Integrated Security=True;Pooling=False";
// SqlConnection con = new SqlConnection(sqlString);
con.Open();
SqlCommand cmd = new SqlCommand("select * from Config Login where User Name='" + textBox1.Text.Trim() + "' and Password='" + textBox2.Text.Trim() + "'", con);
 

SqlDataReader rdr = cmd.ExecuteReader();
rdr.Read();

if (rdr.HasRows)
{

Config_admin_screen f = new Config_admin_screen();
f.Show();
}
}
 
Please do replay me me as early as possible..
 
Thanks
Pradeep CBZ

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 CPallini 155
3 PIEBALDconsult 150
4 BillWoodruff 148
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 8 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100