Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't Convert SQL Select Query Result to Bit

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
}
like image 760
Shadouspan Avatar asked May 28 '26 08:05

Shadouspan


1 Answers

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 + "'";
like image 90
Gordon Linoff Avatar answered May 30 '26 21:05

Gordon Linoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!