2)如何求在dataset中某一列的值?dataset.Tables["tableName"].Rows[index]["columnName"]

解决方案 »

  1.   

    SqlDataAdapter catDA = new SqlDataAdapter("SELECT CategoryID, CategoryName FROM Categories", nwindConn);       catDA.UpdateCommand = new SqlCommand("UPDATE Categories SET CategoryName = @CategoryName " +
                                         "WHERE CategoryID = @CategoryID" , nwindConn);catDA.UpdateCommand.Parameters.Add("@CategoryName", SqlDbType.NVarChar, 15, "CategoryName");SqlParameter workParm = catDA.UpdateCommand.Parameters.Add("@CategoryID", SqlDbType.Int);
    workParm.SourceColumn = "CategoryID";
    workParm.SourceVersion = DataRowVersion.Original;DataSet catDS = new DataSet();
    catDA.Fill(catDS, "Categories");   DataRow cRow = catDS.Tables["Categories"].Rows[0];
    cRow["CategoryName"] = "New Category";catDA.Update(catDS);
      

  2.   

    如果是求和
    不如写条SQL
    "select sum() from tableName"
    在数据库中用视图、存储过程均可以dataset.tables[].select方法不知道行不行
      

  3.   

    楼上的朋友我的问题是在dataset中求某一列的和!对database求某一列的和可以用sql来解决。
      

  4.   

    int sum=0;
    for(i=0;i<dataset.tables[].rows.count;i++)
    {
      sum+=int.parse(dataset.tables[].rows[i]["columnName"].tostring());
    }
    楼主,试一下先,应该是可以的