private void btnFindOK_Click(object sender, EventArgs e)
{
string P_Str_cmdtxt = "select StockID as '库存ID',GoodsID as '商品ID',GoodsName as '商品名称',DepotName as '仓库名称',CompanyName as '供应商名称',StockNum as '库存数量',AlarmNum as '报警数量',GoodsUnit as '商品单位',GoodsTime as '进货时间',GoodsSpec as '商品规格',GoodsPrice as '进货价格',SellPrice as '销售价格',Needpay as '应付金额', Haspay as '实付金额',Re as '备注' from tb_Stock" + P_Str_select;
string P_Str_select = "where GoodsName like '%" + this.txtGoodsName.Text + "%' and GoodsID like '%" + this.txtGoodsID.Text + "%' and StockNum like '%" + this.txtStockNum.Text + "%' and AlarmNum like '%" + this.txtAlarmNum.Text + "%'";
if(this.txtGoodsPrice.Text!="")
{
P_Str_select += " and GoodsPrice" + this.cbxCondition1.Items[this.cbxCondition1.SelectedIndex].ToString() + this.txtGoodsPrice.Text + "";
}
}
出现当前上下文中不存在名称“P_Str_select”??望指教~~
{
string P_Str_cmdtxt = "select StockID as '库存ID',GoodsID as '商品ID',GoodsName as '商品名称',DepotName as '仓库名称',CompanyName as '供应商名称',StockNum as '库存数量',AlarmNum as '报警数量',GoodsUnit as '商品单位',GoodsTime as '进货时间',GoodsSpec as '商品规格',GoodsPrice as '进货价格',SellPrice as '销售价格',Needpay as '应付金额', Haspay as '实付金额',Re as '备注' from tb_Stock" + P_Str_select;
string P_Str_select = "where GoodsName like '%" + this.txtGoodsName.Text + "%' and GoodsID like '%" + this.txtGoodsID.Text + "%' and StockNum like '%" + this.txtStockNum.Text + "%' and AlarmNum like '%" + this.txtAlarmNum.Text + "%'";
if(this.txtGoodsPrice.Text!="")
{
P_Str_select += " and GoodsPrice" + this.cbxCondition1.Items[this.cbxCondition1.SelectedIndex].ToString() + this.txtGoodsPrice.Text + "";
}
}
出现当前上下文中不存在名称“P_Str_select”??望指教~~
string P_Str_cmdtxt = "select StockID as '库存ID',GoodsID as '商品ID',GoodsName as '商品名称',DepotName as '仓库名称',CompanyName as '供应商名称',StockNum as '库存数量',AlarmNum as '报警数量',GoodsUnit as '商品单位',GoodsTime as '进货时间',GoodsSpec as '商品规格',GoodsPrice as '进货价格',SellPrice as '销售价格',Needpay as '应付金额', Haspay as '实付金额',Re as '备注' from tb_Stock " ;
string P_Str_select = "where GoodsName like '%" + this.txtGoodsName.Text + "%' and GoodsID like '%" + this.txtGoodsID.Text + "%' and StockNum like '%" + this.txtStockNum.Text + "%' and AlarmNum like '%" + this.txtAlarmNum.Text + "%'";
P_Str_cmdtxt += P_Str_select ;
{
string P_Str_select = "where GoodsName like '%" + this.txtGoodsName.Text + "%' and GoodsID like '%" + this.txtGoodsID.Text + "%' and StockNum like '%" + this.txtStockNum.Text + "%' and AlarmNum like '%" + this.txtAlarmNum.Text + "%'";
if(this.txtGoodsPrice.Text!="")
{
P_Str_select += " and GoodsPrice" + this.cbxCondition1.Items[this.cbxCondition1.SelectedIndex].ToString() + this.txtGoodsPrice.Text + "";
}
string P_Str_cmdtxt = "select StockID as '库存ID',GoodsID as '商品ID',GoodsName as '商品名称',DepotName as '仓库名称',CompanyName as '供应商名称',StockNum as '库存数量',AlarmNum as '报警数量',GoodsUnit as '商品单位',GoodsTime as '进货时间',GoodsSpec as '商品规格',GoodsPrice as '进货价格',SellPrice as '销售价格',Needpay as '应付金额', Haspay as '实付金额',Re as '备注' from tb_Stock" + P_Str_select;
}
你应该把第一段和第二段换换。
{
string P_Str_select = "where GoodsName like '%" + this.txtGoodsName.Text + "%' and GoodsID like '%" + this.txtGoodsID.Text + "%' and StockNum like '%" + this.txtStockNum.Text + "%' and AlarmNum like '%" + this.txtAlarmNum.Text + "%'";
if(this.txtGoodsPrice.Text!="")
{
P_Str_select += " and GoodsPrice" + this.cbxCondition1.Items[this.cbxCondition1.SelectedIndex].ToString() + this.txtGoodsPrice.Text + "";
}
string P_Str_cmdtxt = "select StockID as '库存ID',GoodsID as '商品ID',GoodsName as '商品名称',DepotName as '仓库名称',CompanyName as '供应商名称',StockNum as '库存数量',AlarmNum as '报警数量',GoodsUnit as '商品单位',GoodsTime as '进货时间',GoodsSpec as '商品规格',GoodsPrice as '进货价格',SellPrice as '销售价格',Needpay as '应付金额', Haspay as '实付金额',Re as '备注' from tb_Stock" + P_Str_select;
}
这样的话,跟出来的查询语句是where GoodsName like '%显示器%' and GoodsID like '%%' and StockNum like '%%' and AlarmNum like '%10%' and GoodsPrice<=800and SellPrice<=1500 where附近有语法错误啊??
我估计,Where前少了一个空格