This code was working perfectly fine, today I tried to execute it, and now I am facing this exception:
I have this SQL error :
Exception Details: System.Data.SqlClient.SqlException: The data types text and nvarchar are incompatible in the equal to operator.
My code is:
protected Boolean is_valid(string a, string b) {
SqlConnection connection = getConnection();
SqlCommand cmd = new SqlCommand();
cmd.Connection = connection;
cmd.CommandText = ("SELECT [Email_id] FROM [logintable] WHERE [Email_id] = @a AND [Password]=@b ");
cmd.Parameters.Add("a", SqlDbType.NVarChar).Value = a;
cmd.Parameters.Add("b", SqlDbType.NVarChar).Value = b;
object obj = cmd.ExecuteScalar();
connection.Close();
...
}`
My DB fields type are nvarchar(50)
.
logintable
its just a simple table, i am using SQL express with VS. It has 3 coloumns, with nvarchar(50) as its datatype. and it doesnt allow nulls.
I have tried to resolve this error by changing nvarchar(50)
data type in db to nvarchar(MAX)
. but it didn't make a difference.
Also, I have tried to write my query like this:
cmd.CommandText = ("SELECT [Email_id] FROM [logintable] WHERE Email_id like @a AND Password like @b ");
but, it didnt resolve or make any difference.Please help? Thanks in advance.