I've tried searching around, but most of the answers were about instantiating a list that doesn't exist or otherwise isn't exactly what I'm looking for. Most of the questions I've come across weren't using the "new" keyword.
Here's what I've got:
using (SqlCmd cmd = new SqlCmd("SELECT * FROM [User] WHERE Login = @Login", false))
{
cmd.AddIString....
}
My problem is on that first line. Visual Studio is fine with it until I try to run it. Then it throws an error Object reference not set to an instance of an object
. It threw the error even when it looked like:
using (SqlCmd cmd = new SqlCmd(
"SELECT * " +
"FROM [User] " +
"WHERE Login = @Login", false))
{
// Code here...
}
Any ideas? I've rewritten it, looked at other methods that do the exact same thing, used Google, etc for about 2 hours now with no real result. Closing Visual Studio didn't do anything either, except cause the same problem on code that was working previously.
EDIT: I did say first line, but here it is a bit more clearly (Line 74):
Line 72: {
Line 73: //using (SqlCmd cmd = new SqlCmd("SELECT * FROM [User] WHERE Login = @Login", false))
Line 74: using (SqlCmd cmd = new SqlCmd("SELECT * FROM [User] WHERE Login = @Login", true))
Line 75: {
Line 76: cmd.AddIString("@Login", 100, login);