PDA

Click to See Complete Forum and Search --> : [RESOLVED] Dont understand error message


VBGuy
Oct 7th, 2005, 08:41 AM
Actually, I understand the message, I don't see what the problem is. the error is:

"The type or namespace name 'cmd' could not be found (are you missing a using directive or an assembly reference?)"


Here is the code:

static private void LogError (int AppID)
{
SqlConnection cn;
SqlCommand cmd;
SqlParameter parm;

cn = new SqlConnection();
cn.ConnectionString = ConnectionString;
cmd.CommandType = CommandType.StoredProcedure;
cmd = new SqlCommand("uspInsertErrorLog",cn);

parm = new SqlParameter("@ApplicationCode",SqlDbType.SmallInt);
parm.Value = AppID;
cmd.Parameters.Add parm;

cn.Open();
cmd.ExecuteNonQuery();

}

The error is on the line:

cmd.Parameters.Add parm;

and it refers to the cmd reference. What am I not seeing?

Thanks


RESOLUTION:

I am missing the parens around the 'parm'
the line should be cmd.Paramters.Add (parm);




Added green "resolved" checkmark - Hack

penagate
Oct 10th, 2005, 11:26 AM
That's a common mistake for VB programmers, to leave out the brackets when not trapping a return value ;)

Explanation of the error message:
- In C# when you declare a variable it is just like this
typename variableName;

Because of this, C# recognises this:
cmd.Parameters.Add parm;

as you declaring a variable named "parm" of the type "cmd.Parameters.Add". And, hence, since "cmd" is not an type or namespace but rather a variable, the error is produced.