初学C#,问个傻瓜问题,希望高手给予指导.(急)
我现在在做个小程序,框架中有个Textbox和一个button,我现在想做的是根据Textbox的输入点击button来进行查询.写了如下代码:
String sle = textBox1.Text;
SqlConnection con = new SqlConnection( "server=.;DataBase=ECED_BT;uid=sa;pwd=; ");
con.Open();
SqlDataAdapter adapter = new SqlDataAdapter( "Select * from COPTH where TH005= "+sle,con);
DataSet ds = new DataSet();
adapter.Fill(ds, "COPTH ");
dataGridView1.DataSource = ds;
con.Close();
我所要查询的列是TH005,里面有列值ECED,运行时输ECED,点查询.当运行到adapter.Fill(ds, "COPTH ");报错,列名 'ECED ' 无效。请高手帮我查找下
看是问题出在了那里.谢谢
------解决方案-------------------- "Select * from COPTH where TH005= ' "+sle+ " ' "
------解决方案--------------------try
SqlDataAdapter adapter = new SqlDataAdapter( "Select * from COPTH where TH005= ' "+sle+ " ' ",con);
------解决方案--------------------SqlConnection con = new SqlConnection( "server=.;DataBase=ECED_BT;uid=sa;pwd=; "); 这里应该有点问题.
SqlConnection con = new SqlConnection( "user id=sa;password=;initial catalog=ECED_BT;Data Source=127.0.0.1;Connect Timeout=30 ");
偶也是初学的...提点建议.
------解决方案--------------------如果你数据库里TH005是字符类型,那么
SqlDataAdapter adapter = new SqlDataAdapter( "Select * from COPTH where TH005= ' " +sle + " ' ",con);
如果你数据库里TH005是数字类型,那么
SqlDataAdapter adapter = new SqlDataAdapter( "Select * from COPTH where TH005= " + int.Parse(sle) ,con);