|
-
Oct 7th, 2005, 08:41 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Dont understand error message
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:
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:
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
Last edited by Hack; Oct 7th, 2005 at 12:43 PM.
-
Oct 10th, 2005, 11:26 AM
#2
Re: [RESOLVED] Dont understand error message
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
Code:
typename variableName;
Because of this, C# recognises this:
Code:
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|