LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with a variable in SQL Statement variable

Solved!
Go to solution

Hello

 

I am trying the following query.

 

hstmt = DBActivateSQL(hdbc, "SELECT UserLevel FROM ClassUsers WHERE Password = "+ cadena +"");

 

At this point I recieve this error:

 

Operands of + have illegal types 'pointer to char' and 'pointer to char'.

 

I have tried this:

 

hstmt = DBActivateSQL(hdbc, "SELECT UserLevel FROM ClassUsers WHERE Password = "+ &cadena +"");


hstmt = DBActivateSQL(hdbc, "SELECT UserLevel FROM ClassUsers WHERE Password = '"+ cadena +"'");

 

Still having the same problem.

 

It works fine if I do this.

 

hstmt = DBActivateSQL(hdbc, "SELECT UserLevel FROM UserClass WHERE Password = 'cadena'");

 

Where 'cadena' is treated as a string.

 

Any Ideas?

 

Thanks!

------------------------------------------------------
There is "No C" in spanish.
If you can think it, you can develop it.
0 Kudos
Message 1 of 3
(3,212 Views)
Solution
Accepted by topic author Victor_Pacheco

The Visual Basic method of concatenating strings with the + operator doesn't work in C. You can use a number of ways to do this - here is just a sample:

 

    char string [256] = "SELECT UserLevel FROM ClassUsers WHERE Password = ";

   

    hstmt = DBActivateSQL(hdbc, strcat (string, cadena)); 

 

JR

0 Kudos
Message 2 of 3
(3,198 Views)

Nice One JR.

 

I was using not the VB but the C# .NET method, which I assume is the same as VB way.

 

Yours is the pretty rigth solution, just missig the adding of "'" (apostrophe character) to diferentiate between chars and numbers at any further query which was solved by the using of strcat() again.

 

Thanks for this.

 

Victor

------------------------------------------------------
There is "No C" in spanish.
If you can think it, you can develop it.
0 Kudos
Message 3 of 3
(3,183 Views)