Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
cmd.CommandText = "select fname,mbn,kskill,resume,email from reg where cl="+ddlocation.SelectedItem+"";
this query is not giving result
XML
if (ds.Tables[0].Rows.Count > 0)
           {
               GridView1.DataSource = ds.Tables[0];
               GridView1.DataBind();
           }
           else
           {
               Response.Write("<script> alert('no match found') </script>");
          }

the control is going to else everytime, and another cmd.CommandText = "select fname,mbn,kskill,resume,email from reg where jobtype='" + Ddjobtype.SelectedItem + "'"; query giving a correct result.
i did not understand what the problem is this database is correct no mistake with any field or any column
Posted
Comments
[no name] 17-Mar-13 8:27am    
is "cl" an int? Did you try and run your queries outside of your code? Did they return results then? In your first query, what is the purpose of adding an empty string at the end of the query? Did you try using a parameterized query instead of this SQL injection attack waiting to happen?

1 solution

The chances are that it's to do with the content of the drop down list: when you put quotes around it as in your second example, it works because SQL knows to expect it as a string.

However, it would be a much, much better idea to use a Parametrized query instead:
C#
cmd.CommandText = "SELECT fname,mbn,kskill,resume,email FROM reg WHERE cl=@CL";
cm.Parameters.AddWithValue("@CL", ddlocation.SelectedItem);
This would also help to protect you from accidental or deliberate SQL Injection attacks.
 
Share this answer
 

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