本帖最后由 dapsjj 于 2016-11-18 11:06 编辑
您好,我这种是属于循环的吧?与dataset是无关的吧?
- private void frm1_Load(object sender, EventArgs e)
- {
- try
- {
- connPCDB = cp.GetConString();
- SqlHelper sh = new SqlHelper(connPCDB);
- sh.Param = sh.GetNewParam();
- sh.Param.AddParam("@DISP_TYPE", SqlDbType.Int, 0);
- DataSet ds = sh.ExecuteDatasetSP("GetData", ref sh.Param, 3000);
- setSpreadData(ds.Tables[0]);
- }
- catch (Exception ex)
- {
-
- }
- }
-
- private void setSpreadData(DataTable spdt)
- {
- if (this.sprdMain.ActiveSheet.RowCount > 0)
- {
- this.sprdMain.ActiveSheet.Rows.Count = 0;
- }
- this.sprdMain.ActiveSheet.Rows.Count = spdt.Rows.Count;
- DataRowCollection rows = spdt.Rows;
- int rowCount = rows.Count;
- int nowRow = 0;
- for (int i = 0; i < rowCount; i++)
- {
- sprdMain.ActiveSheet.Cells[nowRow, 0].Value = rows[i]["A列"].ToString();
- sprdMain.ActiveSheet.Cells[nowRow, 1].Value = rows[i]["B列"].ToString();
- sprdMain.ActiveSheet.Cells[nowRow, 2].Value = rows[i]["C列"].ToString();
- sprdMain.ActiveSheet.Cells[nowRow, 3].Value = rows[i]["D列"].ToString();
-
- nowRow++;
- }
-
- }
复制代码
|