DataView dv = new DataView();
dv.Table = ds.Tables[0];
//MessageBox.Show(SelectName);
dv.RowFilter = "ProdShortName LIKE'%"+SelectName.Trim()+"%'";
DataSet dsView = new DataSet();我这样是不是能查询出来一个结果集?要是能查出来的话怎么把结果集给一个dataset。如果查不出来应该怎么查询,怎么传给dataset。
希望高手帮看下,指导一下。
如果没有的话drs里面就没有值
因为我要用dataset做参数,所以必须把模糊查询出来的结果给一个dataset。
这个方法行的通吗?
你是用 for(int i = 0;i < ds.Tables[0].Rows.Count;i++)
应该用ds.Tables[0].Rows[i] == null
就行了吧
public void setSpreadData(DataSet ds)
{
int cell = 0;
int n = 1;
int k = 5;
double CountPlan = 0;
double CountMake = 0;
cell = Convert.ToInt32(ds.Tables[0].Rows[0]["TimeZone"]);
this.fpSpread1.ActiveSheet.Cells[3*n,0].Text = ds.Tables[0].Rows[0]["ProdName"].ToString();
this.fpSpread1.ActiveSheet.Cells[3*n,cell+5].Text = ds.Tables[0].Rows[0]["PlanCount"].ToString();
this.fpSpread1.ActiveSheet.Cells[3*n,3].Text=ds.Tables[0].Rows[0]["JAN"].ToString();
this.fpSpread1.ActiveSheet.Cells[3*n,4].Text=ds.Tables[0].Rows[0]["ProdShortName"].ToString();
this.fpSpread1.ActiveSheet.Cells[3*n+1,cell+5].Text=ds.Tables[0].Rows[0]["ActtlyMakeQty"].ToString();
try
{
for(int i = 1;i<count;i++)
{
if(ds.Tables[0].Rows[i].IsNull(3))
{
break;
}
if(ds.Tables[0].Rows[i-1]["JAN"].ToString() == ds.Tables[0].Rows[i]["JAN"].ToString())
{
cell = Convert.ToInt32(ds.Tables[0].Rows[i]["TimeZone"]);
this.fpSpread1.ActiveSheet.Cells[3*n,cell+5].Text = ds.Tables[0].Rows[i]["PlanCount"].ToString();
this.fpSpread1.ActiveSheet.Cells[3*n+1,cell+5].Text = ds.Tables[0].Rows[i]["ActtlyMakeQty"].ToString();
}
else
{
n=n+1;
cell = Convert.ToInt32(ds.Tables[0].Rows[i]["TimeZone"]);
this.fpSpread1.ActiveSheet.Cells[3*n,cell+5].Text = ds.Tables[0].Rows[i]["PlanCount"].ToString();
this.fpSpread1.ActiveSheet.Cells[3*n,0].Text = ds.Tables[0].Rows[i]["ProdName"].ToString();
this.fpSpread1.ActiveSheet.Cells[3*n,3].Text=ds.Tables[0].Rows[i]["JAN"].ToString();
this.fpSpread1.ActiveSheet.Cells[3*n,4].Text=ds.Tables[0].Rows[i]["ProdShortName"].ToString();
this.fpSpread1.ActiveSheet.Cells[3*n+1,cell+5].Text = ds.Tables[0].Rows[i]["ActtlyMakeQty"].ToString();
}
}
}
catch(Exception e)
{
MessageBox.Show(e.ToString());
}
//史恩光 2008/12/1 追加 ↓
for(k=5;k<29;k++)
{
for(int sum = 1;sum<countJan;sum++)
{
if(this.fpSpread1.ActiveSheet.Cells[3*sum,k].Text !="")
{
CountPlan = CountPlan+Convert.ToDouble(this.fpSpread1.ActiveSheet.Cells[3*sum,k].Text);// directive total
this.fpSpread1_Sheet1.Cells[0,k].Text = CountPlan.ToString(); //set first row's text
}
if(this.fpSpread1.ActiveSheet.Cells[3*sum+1,k].Text !="")
{
CountMake = CountMake + Convert.ToDouble(this.fpSpread1.ActiveSheet.Cells[3*sum+1,k].Text);
this.fpSpread1_Sheet1.Cells[1,k].Text = CountMake.ToString();
}
}
CountMake = 0;
CountPlan = 0;
}
//史恩光 2008/12/1 追加 ↑
}public void pictureBox7_Click(object sender, System.EventArgs e)
{
DataView dv = new DataView();
dv.Table = ds.Tables[0];
DataSet dsView = new DataSet();
DataRow [] drs = ds.Tables[0].Select("ProdShortName LIKE'%"+SelectName.Trim()+"%'");
dsView.Merge(drs);
setSpreadData(dsView);
}
这句,当i= 5的时候。就是没有值了,所以就跳到catch里面了。
break;
上面不是说了?
if(ds.Tables[0].Rows[i].IsNull)
break;
try
{
count = ds.Tables[0].Rows.Count;//在这里为count 重新负值就OK了
for(int i = 1;i<count;i++)
{
if(ds.Tables[0].Rows[i].IsNull(3))
{
break;
}
if(ds.Tables[0].Rows[i-1]["JAN"].ToString() == ds.Tables[0].Rows[i]["JAN"].ToString())
{
cell = Convert.ToInt32(ds.Tables[0].Rows[i]["TimeZone"]);
this.fpSpread1.ActiveSheet.Cells[3*n,cell+5].Text = ds.Tables[0].Rows[i]["PlanCount"].ToString();
this.fpSpread1.ActiveSheet.Cells[3*n+1,cell+5].Text = ds.Tables[0].Rows[i]["ActtlyMakeQty"].ToString();
}
else
{
n=n+1;
cell = Convert.ToInt32(ds.Tables[0].Rows[i]["TimeZone"]);
this.fpSpread1.ActiveSheet.Cells[3*n,cell+5].Text = ds.Tables[0].Rows[i]["PlanCount"].ToString();
this.fpSpread1.ActiveSheet.Cells[3*n,0].Text = ds.Tables[0].Rows[i]["ProdName"].ToString();
this.fpSpread1.ActiveSheet.Cells[3*n,3].Text=ds.Tables[0].Rows[i]["JAN"].ToString();
this.fpSpread1.ActiveSheet.Cells[3*n,4].Text=ds.Tables[0].Rows[i]["ProdShortName"].ToString();
this.fpSpread1.ActiveSheet.Cells[3*n+1,cell+5].Text = ds.Tables[0].Rows[i]["ActtlyMakeQty"].ToString();
}
}
解决了,谢谢你们了