Click here to Skip to main content
15,900,589 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
dbCommand = new SqlCommand("SELECT CountryName, Results.CountryId FROM Results,Country WHERE Country.CountryId = Results.CountryId AND GameId '" + cboGameID.SelectedValue + "'", dbConnection);

dbAdapter = new SqlDataAdapter(dbCommand);
dsResults = new DataSet();
dbAdapter.Fill(dsResults, "results");
cboCountryName.DataSource = dsResults.Tables["results"];
cboCountryName.DisplayMember = "CountryName";
Posted

SQL
AND GameId '" + cboGameID.SelectedValue + "'", dbConnection);

You need an equal to after the field GameId -> AND GameId = '" + cboGamied.SelectedValue...
 
Share this answer
 
Comments
Sander Rossel 16-Oct-11 17:32pm    
That would probably be it, +5. See my answer for another big mistake in the code though ;)
Abhinav S 17-Oct-11 0:26am    
Yup will do.
Well Abhinav probably gave you the right answer already. I want to add though that doing what you are doing is not a good practice. You should aways parameterize your queries for performance and safety (all those SQL injection attacks you've been hearing about were caused by queries that were not parameterized!) ;)
Try the following instead!
C#
dbCommand = new SqlCommand("SELECT CountryName, Results.CountryId FROM Results,Country WHERE Country.CountryId = Results.CountryId AND GameId = @GameId '");
cmd.Parameters.AddWithValue("@GameId", cboGameID.SelectedValue);

@GameId will be replaced with the value you specified in the parameter and SqlServer does the rest :)
No SQL injection, no performance hit, your query will be cached, your code looks cleaner, everyone wins!

Hope that helps :)
 
Share this answer
 
Comments
Abhinav S 17-Oct-11 0:26am    
Good point. 5.

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