gridview数据绑定时列名无效 [英] Invalid Column Name while gridview databinding
本文介绍了gridview数据绑定时列名无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Gridview面板,它实际上试图绑定过滤的价值。
以下是我的代码。
Hi,
I''m having a Gridview panel which actually trying to bind the value of filtering.
Below are my code.
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con.Open();
string ddl = DropDownList1.Text;
string str = "select * from Peripheral where BelongsTo = "+ddl+"";
SqlCommand cmd = new SqlCommand(str, con);
SqlDataReader result = cmd.ExecuteReader();
GridView1.DataSource = result;
GridView1.DataBind();
result.Close();
con.Close();
但是当我开始调试时,出现了一个显示无效列的错误名字General,我的ddl = General。
but when i start to debug, there''s an error which showing invalid column name "General" which my ddl = General.
推荐答案
试试这个:
Try this:
string str = "select * from Peripheral where BelongsTo = '" + ddl + "'";
>
这篇关于gridview数据绑定时列名无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文