目的:查询DATAGRID当前表中的序号为1所有记录;_________________________________________
private void button1_Click(object sender, System.EventArgs e)
{
string tablestr;
SqlConnection thisconnection=new SqlConnection("Server=(local);Integrated Security=SSPI;"+ "Initial Catalog=aohome");
tablestr=this.dataGrid1.DataMember.ToString();
this.sqlSelectCommand1.CommandText="select * from" +tablestr+"where 序号='1'";
this.dataSet11.Clear();
this.sqlDataAdapter1.Fill(this.dataSet11,tablestr);
dataGrid1.SetDataBinding(this.dataSet11,tablestr);
}_____________________________________
出错信息:未处理的“System.Data.SqlClient.SqlException”类型的异常出现在 system.data.dll 中。其他信息: 系统错误。错误定位语句:this.sqlDataAdapter1.Fill(this.dataSet11,tablestr);
________________
调试1:this.sqlSelectCommand1.CommandText="select * from "+tablestr+" order by 序号 "+sortstr;可以对数据库排序,没报错.
调试2:this.sqlSelectCommand1.CommandText="select 序号 from" +tablestr;
仍然报错.
private void button1_Click(object sender, System.EventArgs e)
{
string tablestr;
SqlConnection thisconnection=new SqlConnection("Server=(local);Integrated Security=SSPI;"+ "Initial Catalog=aohome");
tablestr=this.dataGrid1.DataMember.ToString();
this.sqlSelectCommand1.CommandText="select * from" +tablestr+"where 序号='1'";
this.dataSet11.Clear();
this.sqlDataAdapter1.Fill(this.dataSet11,tablestr);
dataGrid1.SetDataBinding(this.dataSet11,tablestr);
}_____________________________________
出错信息:未处理的“System.Data.SqlClient.SqlException”类型的异常出现在 system.data.dll 中。其他信息: 系统错误。错误定位语句:this.sqlDataAdapter1.Fill(this.dataSet11,tablestr);
________________
调试1:this.sqlSelectCommand1.CommandText="select * from "+tablestr+" order by 序号 "+sortstr;可以对数据库排序,没报错.
调试2:this.sqlSelectCommand1.CommandText="select 序号 from" +tablestr;
仍然报错.
this.sqlSelectCommand1.CommandText="select 序号 from" +tablestr;为:
this.sqlSelectCommand1.CommandText="select 序号 from " +tablestr;少了一个空格
调试1:this.sqlSelectCommand1.CommandText="select * from "+tablestr+" order by 序号 "+sortstr;可以对数据库排序,没报错.
仍然报错.