Click here to Skip to main content
16,004,887 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I want set parameter value in Select Mysql query in C#.
my query is:
C#
SELECT @param1:=id  FROM `X` WHERE nation_code='8989899';

this is trust query in sql section in PHPMyAdmin.
in C# ,I create command and add parameter to it
C#
command.Parameters.Add("@param1",MySql.Data.MySqlClient.MySqlDbType.String);

but when execute query recive syntax error near
C#
:=id  FROM 

I changed := to = .query execute but @param1 will be NULL

thank's for your replay
Posted

 
Share this answer
 
Comments
ali majed 19-Oct-13 3:00am    
thank for reply but parameter is output not input .i want put id in @param1
Mehdi Gholam 19-Oct-13 5:15am    
Try this : http://stackoverflow.com/questions/9195174/stored-procedures-with-mysql-connector-in-c-sharp
ali majed 20-Oct-13 7:29am    
I know stored procedure but is there another way?
I test another way "SELECT id INTO @param1" but again run in PHPMyAdmin and get syntax error in C#
Mehdi Gholam 20-Oct-13 7:30am    
Read the link and see how the output parameters are used.
ali majed 20-Oct-13 7:50am    
it's OK but i don''t want use parameter in C# .I want use it in next query .in other word get id and use in next insert query and I want send all this in one command text. so it's not helpful get in C# value . I must access parameter in next query in next line
try this :

if you want to send a parameter to Sql u should change your query to

SQL
SELECT id=@parameter  FROM `X` WHERE nation_code='8989899';



also change your c# code to :

C#
string YourValue="Somthing";
command.Parameters.AddWithValue("@param1",YourValue);
 
Share this answer
 
v2
Comments
ali majed 19-Oct-13 3:04am    
thank for reply but parameter is output not input .i want put id in @param1

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900