Your problem is telling you that the variable (object) that you are trying to use, does not exist in your
context. A quite possible problems that can raise this are,
1. Identifier case-sensitive
C# is a case-sensitive language, so
Command
and
command
are two different objects.
SqlCommand command = new SqlCommand("sql command", connection);
Command.Parameters.Add(new SqlParameter("", ""));
So, from this you should check if this is the case.
2. Scope[^]
You should always consider checking the scope of the variables, such as if else block. If a variable is generated in one code block, it won't be available under second.
if(condition) {
SqlCommand Command = new SqlCommand("sql command", connection);
} else {
SqlCommand Command = new SqlCommand("other command", connection);
}
Command.Parameters.Add(new SqlParameter("", ""));
The same error gets popped in the other scenario, because the object Command is deleted as soon as the code hits the closing braces.
Check for what is the possible problem in your code. Otherwise,
debug your application[
^]. :)