Setting an instance object equal to my empty string.
-
I can't explain it properly in the subject section, it's not as simple as that. Here is the code snippet in question.
UserPass = reader["Password"].ToString();
So UserPass is my string variable and reader is an SqlReader object. Here is it being instantiated:
SqlDataReader reader = myCommand.ExecuteReader();
(myCommand is an SqlCommand obj)
reader["Password"]
Password is a column name in my Sql DB. Basically I've just told the reader to go look within that column and used a query to specify where abouts. I want to set the reader["Password"] equal to an empty string to compare against user input. Now there aren't any errors when I do this but it does throw an exception:
An exception of type 'System.InvalidOperationException' occurred in System.Data.dll but was not handled in user code
It doesn't give much more detail other than that and I'm not entirely sure what's wrong.
-
I can't explain it properly in the subject section, it's not as simple as that. Here is the code snippet in question.
UserPass = reader["Password"].ToString();
So UserPass is my string variable and reader is an SqlReader object. Here is it being instantiated:
SqlDataReader reader = myCommand.ExecuteReader();
(myCommand is an SqlCommand obj)
reader["Password"]
Password is a column name in my Sql DB. Basically I've just told the reader to go look within that column and used a query to specify where abouts. I want to set the reader["Password"] equal to an empty string to compare against user input. Now there aren't any errors when I do this but it does throw an exception:
An exception of type 'System.InvalidOperationException' occurred in System.Data.dll but was not handled in user code
It doesn't give much more detail other than that and I'm not entirely sure what's wrong.
Nothing you provided looks obviously wrong. Which statement throws the Exception? We may need to see the query. And provide the code in proper order.
-
I can't explain it properly in the subject section, it's not as simple as that. Here is the code snippet in question.
UserPass = reader["Password"].ToString();
So UserPass is my string variable and reader is an SqlReader object. Here is it being instantiated:
SqlDataReader reader = myCommand.ExecuteReader();
(myCommand is an SqlCommand obj)
reader["Password"]
Password is a column name in my Sql DB. Basically I've just told the reader to go look within that column and used a query to specify where abouts. I want to set the reader["Password"] equal to an empty string to compare against user input. Now there aren't any errors when I do this but it does throw an exception:
An exception of type 'System.InvalidOperationException' occurred in System.Data.dll but was not handled in user code
It doesn't give much more detail other than that and I'm not entirely sure what's wrong.
did you debug to identify on which line you had the issue?
Mark the answer as accepted if that worked for you :). And for down-voters please specify the reason to improve the solution :).