Click here to Skip to main content
15,899,679 members
Home / Discussions / C#
   

C#

 
GeneralRe: Single Sign On question Pin
Etienne_12324-Jun-10 1:38
Etienne_12324-Jun-10 1:38 
GeneralRe: Single Sign On question Pin
Etienne_12315-Jul-10 23:50
Etienne_12315-Jul-10 23:50 
QuestionPurpose of Web Service Namespaces Pin
AspDotNetDev21-May-10 10:29
protectorAspDotNetDev21-May-10 10:29 
AnswerRe: Purpose of Web Service Namespaces Pin
Pete O'Hanlon21-May-10 12:34
mvePete O'Hanlon21-May-10 12:34 
GeneralRe: Purpose of Web Service Namespaces Pin
AspDotNetDev21-May-10 12:40
protectorAspDotNetDev21-May-10 12:40 
AnswerRe: Purpose of Web Service Namespaces Pin
Jürgen Röhr22-May-10 1:42
professionalJürgen Röhr22-May-10 1:42 
QuestionHow to work on VOIP, Video Conferencing, Chat room using either intranet or internet system Pin
CoderForEver21-May-10 9:02
CoderForEver21-May-10 9:02 
QuestionDatabase Query Error: {"Must declare the scalar variable \"@UserId\"."}...has me baffled Pin
PDTUM21-May-10 8:13
PDTUM21-May-10 8:13 
Hello,

I am using VS 2008 (C#) and I am running what would seem to be a very simple query to identify a users activity on a client server network. I am trying to extract a single value from a data table, but I am getting an error that I cannot understand. It seems so simple that I am baffled by the error. Here is the error and the code that generated it.

the error: {"Must declare the scalar variable \"@UserId\"."}

the code:

SqlConnection Conn = new SqlConnection(CONNSTR);

            try
            {
                //Check for Active from Online Status

                string Sql = "SELECT [IsActive] FROM SqlCodeGen " +
                    "WHERE [UserId] = @UserId AND [RegNumber] = @RegNumber AND [UnlockCode] = @UnlockCode ";

                SqlCommand Comm = new SqlCommand(Sql, Conn);  //Apply Command 
                Comm.CommandType = CommandType.Text;

                //Parameters
                Comm.Parameters.Clear();
                Comm.Parameters.AddWithValue("@UserId", theUser );
                Comm.Parameters.AddWithValue("@UnlockCode", theUnlockCode );
                Comm.Parameters.AddWithValue("@RegNumber", theRegNumber );

                SqlDataAdapter da = new SqlDataAdapter(Sql, Conn);
                DataSet ds = new DataSet();
                da.Fill(ds);  


This is where the error occurs. Now, the parameter is clearly defined and a step by step evaluation shows that it is not null. If I remove all the parameters, the code block runs fine. If I remove just the error parameter, the next one reports the same issue. I do not understand why the SQL call does not see the parameters. Thank you in advance...Pat

ps: If I remove the parameters and hard code the variables into the query, it works perfect (ex: + "'" + theUser + "'")....but I hate the way it looks and I want to know why the correct way does not work!
AnswerRe: Database Query Error: {"Must declare the scalar variable \"@UserId\"."}...has me baffled Pin
William Winner21-May-10 8:21
William Winner21-May-10 8:21 
AnswerRe: Database Query Error: {"Must declare the scalar variable \"@UserId\"."}...has me baffled Pin
PDTUM21-May-10 9:17
PDTUM21-May-10 9:17 
AnswerRe: Database Query Error: {"Must declare the scalar variable \"@UserId\"."}...has me baffled Pin
Dimitri Witkowski21-May-10 8:22
Dimitri Witkowski21-May-10 8:22 
AnswerRe: Database Query Error: {"Must declare the scalar variable \"@UserId\"."}...has me baffled Pin
PDTUM21-May-10 9:12
PDTUM21-May-10 9:12 
Questionreference can't be found works while in visual studio, but not outside Pin
aei_totten21-May-10 8:07
aei_totten21-May-10 8:07 
QuestionCalling non .net cpp app functions from c# app Pin
JollyGiant196821-May-10 6:22
JollyGiant196821-May-10 6:22 
AnswerRe: Calling non .net cpp app functions from c# app Pin
dan!sh 21-May-10 6:43
professional dan!sh 21-May-10 6:43 
GeneralRe: Calling non .net cpp app functions from c# app Pin
JollyGiant196821-May-10 7:36
JollyGiant196821-May-10 7:36 
AnswerRe: Calling non .net cpp app functions from c# app Pin
Dimitri Witkowski21-May-10 6:44
Dimitri Witkowski21-May-10 6:44 
GeneralRe: Calling non .net cpp app functions from c# app Pin
JollyGiant196821-May-10 7:37
JollyGiant196821-May-10 7:37 
GeneralRe: Calling non .net cpp app functions from c# app Pin
Dimitri Witkowski21-May-10 7:39
Dimitri Witkowski21-May-10 7:39 
AnswerRe: Calling non .net cpp app functions from c# app Pin
Luc Pattyn21-May-10 7:23
sitebuilderLuc Pattyn21-May-10 7:23 
GeneralRe: Calling non .net cpp app functions from c# app Pin
JollyGiant196821-May-10 7:34
JollyGiant196821-May-10 7:34 
AnswerRe: Calling non .net cpp app functions from c# app Pin
David Knechtges21-May-10 7:49
David Knechtges21-May-10 7:49 
GeneralRe: Calling non .net cpp app functions from c# app Pin
Luc Pattyn21-May-10 8:07
sitebuilderLuc Pattyn21-May-10 8:07 
QuestionSending Parameter Pin
future383921-May-10 5:42
future383921-May-10 5:42 
AnswerRe: Sending Parameter Pin
harold aptroot21-May-10 6:09
harold aptroot21-May-10 6:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.