Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
mycnOptionPanel.Open();
                  mycmdOptionPanel = mycnOptionPanel.CreateCommand();
                  mycmdOptionPanel.CommandText = "select Device_ID from DEVICE_INFO where Device_name=@Device_name";
                    mycmdOptionPanel.Parameters.AddWithValue("@Device_name",LabelDeviceName.Text);
           string strDeviceID =Convert.ToString(mycmdOptionPanel.ExecuteScalar());



This is my query but it return nothing in strDeviceID i.e just show strDeviceID="" when debug. I am using Mysql database with asp.net4.0 c#, and my connetor is
mysql-connector-odbc-5.1.13-win32 is this problem of this connetor means is it required other query format ? because before this i used mysql-connector-NET and query works.
I want to do this with mysql-connector-odbc connector.
if i used "'"+textbox.text+"'" directly in qurey then it works but its allow sqlinjection,
so plz give any solution, thank you.
Posted
Updated 24-Aug-15 19:02pm
v3
Comments
AbidHussain128 25-Aug-15 0:46am    
Hi,
At following line.
mycmdOptionPanel.Parameters.AddWithValue("@Device_name", "'"+LabelDeviceName.Text+"'");

Remove "'" when passing value.
Update line with:
mycmdOptionPanel.Parameters.AddWithValue("@Device_name", LabelDeviceName.Text);
Member 11922776 25-Aug-15 1:00am    
hey sorry i tried that but not work. i posted my updated query,but not work. i updated in question as my original query is same as u mentioned, sorry again.

1 solution

try with
C#
mycnOptionPanel.Open();
mycmdOptionPanel = mycnOptionPanel.CreateCommand();
mycmdOptionPanel.CommandText = "select Device_ID from DEVICE_INFO where Device_name=?";               mycmdOptionPanel.Parameters.AddWithValue("@Device_name",LabelDeviceName.Text);
string strDeviceID =Convert.ToString(mycmdOptionPanel.ExecuteScalar());
 
Share this answer
 
v2
Comments
Member 11922776 25-Aug-15 1:07am    
i did same. but not work.
DamithSL 25-Aug-15 1:21am    
are you sure that you need to read from label? or textbox? debug and check the value in runtime whether you have correct value for device name
Member 11922776 25-Aug-15 1:25am    
yes i want to read from label.means i access device name value from Mysql database and assign it to label then use that value in mycmdOptionPanel.Parameters.AddWithValue("@Device_name", LabelDeviceName.Text);

is it problem of connetor?
DamithSL 25-Aug-15 1:30am    
check my updated answer, one last attempt, try with ? instead of @Device_name in sql statement
Member 11922776 25-Aug-15 1:38am    
It's showing exception that : Parameter '?' must be defined.

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