command returning null value
-
string connection = ConfigurationManager.AppSettings["connectionstring"]; SqlConnection con = new SqlConnection(connection); con.Open(); SqlCommand cmd = new SqlCommand("select place_name from place inner join state on place.state_id=state.state_id where state_name ='" + statedpdwnlist.SelectedItem.Value + "'", con); dr = cmd.ExecuteReader(); con.close(); I cannot figure out why the above command is returning null value eventhough it is giving the desired output whn the same command is run on sql server query analyser.Can anybody help me with this??????( statedpdwnlist.SelectedItem.Value is coming correct in the query)
-
string connection = ConfigurationManager.AppSettings["connectionstring"]; SqlConnection con = new SqlConnection(connection); con.Open(); SqlCommand cmd = new SqlCommand("select place_name from place inner join state on place.state_id=state.state_id where state_name ='" + statedpdwnlist.SelectedItem.Value + "'", con); dr = cmd.ExecuteReader(); con.close(); I cannot figure out why the above command is returning null value eventhough it is giving the desired output whn the same command is run on sql server query analyser.Can anybody help me with this??????( statedpdwnlist.SelectedItem.Value is coming correct in the query)
Have you copied the SQL in the debugger to make sure it's exactly right and works in QA ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
string connection = ConfigurationManager.AppSettings["connectionstring"]; SqlConnection con = new SqlConnection(connection); con.Open(); SqlCommand cmd = new SqlCommand("select place_name from place inner join state on place.state_id=state.state_id where state_name ='" + statedpdwnlist.SelectedItem.Value + "'", con); dr = cmd.ExecuteReader(); con.close(); I cannot figure out why the above command is returning null value eventhough it is giving the desired output whn the same command is run on sql server query analyser.Can anybody help me with this??????( statedpdwnlist.SelectedItem.Value is coming correct in the query)
myinstincts wrote:
SqlCommand cmd = new SqlCommand("select place_name from place inner join state on place.state_id=state.state_id where state_name ='" + statedpdwnlist.SelectedItem.Value + "'", con);
Do like this :
string S="select place_name from place inner join state on place.state_id=state.state_id where state_name ='" + statedpdwnlist.SelectedItem.Value + "'"
SqlCommand cmd = new SqlCommand(s, con);Now, Put a breakpoint on String S line, check the value of S. Then put the same string on SQL Server Query window and check the result. This will clear your doubts !
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
-
Have you copied the SQL in the debugger to make sure it's exactly right and works in QA ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
Sorry I didn't see your reply before I post. :doh:
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
-
Sorry I didn't see your reply before I post. :doh:
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
*grin* probably because it wasn't there and you put more time in to your reply.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.