DataView dv = new DataView();
dv.Table = ds.Tables[0];
//MessageBox.Show(SelectName);
dv.RowFilter = "ProdShortName LIKE'%"+SelectName.Trim()+"%'";
DataSet dsView = new DataSet();我这样是不是能查询出来一个结果集?要是能查出来的话怎么把结果集给一个dataset。如果查不出来应该怎么查询,怎么传给dataset。
希望高手帮看下,指导一下。

解决方案 »

  1.   

    直接 DataRow [] drs  = ds.Tables[0].Select("ProdShortName LIKE'%"+SelectName.Trim()+"%'");
      如果没有的话drs里面就没有值
      

  2.   

    这样的话存的只是SelectName一个字段。还是有SelectName的整个行都保存了?
      

  3.   

    DataRow [] drs 这个市什么意思啊。没用过不懂啊。这个东西查出来的能付给dataset吗?
    因为我要用dataset做参数,所以必须把模糊查询出来的结果给一个dataset。
    这个方法行的通吗?
      

  4.   

    再问你个问题啊。如果我的dataset里面只有5行数据。怎么判断第六行为null啊
      

  5.   

    就是到第六行的时候就让for循环停止。6是循环变量
      

  6.   

     一般都这样遍历的foreach(DataRow dr in ds.Tables[0].Rows)
    你是用 for(int i = 0;i < ds.Tables[0].Rows.Count;i++)
       
    应该用ds.Tables[0].Rows[i] == null
    就行了吧
      

  7.   


    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);
    }
      

  8.   

    for(int i = 1;i<count;i++)
    这句,当i= 5的时候。就是没有值了,所以就跳到catch里面了。
      

  9.   

    if(ds.Tables[0].Rows[i]== null)
    break;
    上面不是说了?
      

  10.   

    1:DataRow.IsNull2:Convert.IsDBNull
    if(ds.Tables[0].Rows[i].IsNull) 
    break; 
      

  11.   


    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();
                                                    }
                        }    
        
    解决了,谢谢你们了