日期:2014-05-18  浏览次数:20933 次

到底哪错了
下面代码哪错了   一个下午啊  
private   void   DataBind()
{
//函数DataBind
string   strConn= "server=192.168.1.105;database=111;uid=sa;pwd= ";  
SqlConnection   myConn=new   SqlConnection(strConn);  
string   strCom;  
strCom   =   "SELECT   序号,代号,图样编号,名称,数量,最低价,最高价,备注   FROM   表   ";  
SqlCommand   forumCommand   =new   SqlCommand(strCom,myConn);  
sqlDataAdapter1=new   SqlDataAdapter();  
DataSet3   dataSet31=   new   DataSet3();  
sqlDataAdapter1.SelectCommand   =forumCommand;
sqlDataAdapter1.Fill(dataSet31, "表 ");  
DataView   dv   =   dataSet31.表.DefaultView;
dv.Sort   =   "序号   Desc ";
dataGrid1.DataSource=dv;
}
private   void   textBox1_TextChanged(object   sender,   System.EventArgs   e)
{
string   strConn= "server=191.168.1.105;database=111;uid=sa;pwd= ";  
SqlConnection   myConn   =   new   SqlConnection(strConn);
myConn.Open();
string   cxsj   =   this.comboBox1.Text;//运行到这里就出现系统错误
if(cxsj== "序号 ")
{
string   sel= "select   count(*)   from   表   where   序号   like   ' "+this.textBox1.Text.Trim()   + " ' ";
SqlCommand   mycommand=new   SqlCommand(sel,myConn);
int   fla=(int)   mycommand.ExecuteScalar();
if   (fla> 0)
{
string   strSql;
strSql   =   "select     *   from   表   WHERE   (序号   like   '% "+this.textBox1.Text.Trim()   + "% ') ";
SqlCommand   forumCommand   =new   SqlCommand(strSql,myConn);
sqlDataAdapter1=new   SqlDataAdapter();  
DataSet1   dataSet11=   new   DataSet1();  
sqlDataAdapter1.SelectCommand   =forumCommand;    
sqlDataAdapter1.Fill(dataSet11, "表 ");  
DataView   dv   =   dataSet31.表.DefaultView;
dv.Sort   =   "序号   Desc ";
dataGrid1.DataSource=dv;
}
}
}
private   void   clcx_Load(object   sender,   System.EventArgs   e)
{
DataBind();
}

------解决方案--------------------
去掉下面这些代码就好了
string sel= "select count(*) from 表 where 序号 like ' "+this.textBox1.Text.Trim() + " ' ";
SqlCommand mycommand=new SqlCommand(sel,myConn);
int fla=(int) mycommand.ExecuteScalar();
if (fla> 0)
{