3

After the user has registered; the user's membership is saved as "passive" by default. I do this in the following way: I have a line called "active" in my user table and the data type of this field is bit and default value of this field is 0. What I want to do is: If the user has not activated his account, I want him to get warning but I got System.IConvertible error. My login.aspx.cs is as follows:

DataRow drlogin = function.GetDataRow("SELECT isactive FROM user WHERE email = '" + TxtEMail.Text + "'");
if(Convert.ToInt32(drlogin) == 0)
{
    string message = "<script>alert('You can't login because your account is not active!');</script>";
}
else
{
    // Login operations
}
Vadim Kotov
  • 7,766
  • 8
  • 46
  • 61
Shadouspan
  • 253
  • 2
  • 14

3 Answers3

2

First, you should be using parameters, rather than munging the query string with parameter values.

Second, you can convert to the type you want, which appears to be an integer:

SELECT CAST(isactive as int) as isactive
FROM user
WHERE email = '" + TxtEMail.Text + "'";
Gordon Linoff
  • 1,198,228
  • 53
  • 572
  • 709
0

use this SQL Instead your one :

"SELECT ISNULL((SELECT isactive FROM user WHERE email = '" + TxtEMail.Text + "'),0)"
PurTahan
  • 621
  • 9
  • 23
0

This line is toxic, robots will hack your website as soon as you publish it:

DataRow drlogin = function.GetDataRow("SELECT isactive FROM user WHERE email = '" + TxtEMail.Text + "'");

Use parameters and not string concatenation!

You cannot convert DataRow to Int32, besides it is a bit column that should be converted to bool. So it should be like this:

if(!Convert.ToBoolean(drlogin[0]))

or

if(!Convert.ToBoolean(drlogin["isactive"]))
Vojtěch Dohnal
  • 7,378
  • 3
  • 39
  • 99