标示 系统错误,高手来啊,急急急 55555555555
private void button1_Click(object sender, System.EventArgs e)
{
string tradecode = tradeCode.Text;
string tradename = tradeName .Text;
string type = tradeType.Text;
string AddSql= " ";
if(tradecode!= " ")AddSql+= "and tradecode like '% "+tradecode+ "% ";
if(tradename!= " ")AddSql+= "and tradename like '% "+tradename+ "% ";
if(type!= " ")AddSql+= "and type like '% "+type + "% ";
SqlConnection conn= new SqlConnection( "Data Source=(local);DataBase=db_Ewss;Integrated Security=SSPI ");
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter( "select tradecode as [商品编号],tradename as [商品名称],type as [商品类型],unit as [单位],qty as[ 商品数量],price as [最后一次进价],saleprice as [最后一次销价],averageprice as [加权平均价],checkqty as [盘点数量] from tb_stock where type like '% "+type+ "% ' "+AddSql+ " Order by tradecode ",conn);
//FPara.connStr就是组件中的数据库连接字符串
DataSet ds = new DataSet();
sda.Fill(ds, "tb_stock ");
StockCheck.DataSource = ds.Tables[ "tb_stock "].DefaultView;
Rds = ds;
StockCheck.SetDataBinding(ds, "tb_stock ");
}
点击按钮想实现查询,但是显示“
未处理的“
System.Data.SqlClient.SqlException”类型的异常出现在 system.data.dll 中。
其他信息: 系统错误。
”
绿色反光标示 sda.Fill(ds, "tb_stock ");语句
问题处在那里啊?怎么解决啊 ,谢谢拉
------解决方案--------------------if(tradecode!= " ")AddSql+= "and tradecode like '% "+tradecode+ "% ' ";
if(tradename!= " ")AddSql+= "and tradename like '% "+tradename+ "% ' ";
if(type!= " ")AddSql+= "and type like '% "+type + "% ' ";
///不要忘记打结束 '
------解决方案--------------------if(tradecode!= " ")AddSql+= "and tradecode like '% "+tradecode+ "% ";
//你看你代码里 % 后是不是少了个 ' ?
你完全没有看我上面发出的代码嘛。。。。
------解决方案--------------------string tradecode = tradeCode.Text.Trim();
string tradename = tradeName .Text.Trim();
以免别人敲空格