Please can you help me why my command for select dont select any data. I try change select from name to ID and it works but i need that this select work for name select not nly for ID.
Database data:
id user password level
1 Rad3k ..... 0
Script for select:
public bool loginVerification(string name, string password)
{
test = name;
bool access = false;
string checkLogin, checkPassword;
int level;
commandS = new SqlCommand("SELECT * FROM dbo.users WHERE user like @name", conn);
try
{
conn.Open();
commandS.Parameters.Clear();
// Parameters
SqlParameter nameParam = new SqlParameter("@name", SqlDbType.VarChar, 30);
nameParam.Value = name;
commandS.Parameters.Add(nameParam);
commandS.Prepare();
SqlDataReader reader = commandS.ExecuteReader();
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
if (reader.IsDBNull(i))
return access = false;
checkLogin = reader.GetString(1);
checkPassword = reader.GetString(2);
level = reader.GetInt32(3);
if (name == checkLogin && hashPassword.ValidatePassword(password, checkPassword) == true)
access = true;
}
return access;
}
finally
{
conn.Close();
}
}
If i use this select so it works:
commandS = new SqlCommand("SELECT * FROM dbo.users WHERE id = 1", conn);
But when i use this so it dont work:
commandS = new SqlCommand("SELECT * FROM dbo.users WHERE user like @name", conn);
I try use this without parameter, but it dont work too.
commandS = new SqlCommand("SELECT * FROM dbo.users WHERE user like 'Rad3k'", conn);
commandS = new SqlCommand("SELECT * FROM dbo.users WHERE user like '%Rad3k%'", conn);
commandS = new SqlCommand("SELECT * FROM dbo.users WHERE user like 'Rad3k%'", conn);
commandS = new SqlCommand("SELECT * FROM dbo.users WHERE user = 'Rad3k'", conn);
// and same with paramter still dont work
Thanks for all people which can help me.