本文介绍了'System.Data.DataRowView'附近的语法不正确.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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";
推荐答案
AND GameId '" + cboGameID.SelectedValue + "'", dbConnection);
在字段GameId->之后需要一个等于. AND GameId = ''" + cboGamied.SelectedValue
...
You need an equal to after the field GameId -> AND GameId = ''" + cboGamied.SelectedValue
...
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将替换为您在参数中指定的值,而SqlServer会执行其余操作:)
没有SQL注入,没有性能下降,您的查询将被缓存,您的代码看起来更整洁,所有人都赢了!
希望对您有所帮助:)
@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 :)
这篇关于'System.Data.DataRowView'附近的语法不正确.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!