问题描述
dataGridView1.DataSource=null;OleDbConnectioncn;OleDbCommandcm1,cm2;OleDbDataReaderdr1,dr2;OleDbDataAdapteradap1,adap2;stringmdbPath=@"MiddleVoltage.mdb";stringstrConn="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+mdbPath;stringstrSQL1="select*fromResult";stringstrSQL2="selectLineNameas线路名称,PLas配线网损所占比例,PTas配变网损所占比例,P0as配变空损所占比例FROMAnalysis";cn=newOleDbConnection(strConn);cn.Open();cm1=newOleDbCommand(strSQL1,cn);cm2=newOleDbCommand(strSQL2,cn);adap1=newOleDbDataAdapter(strSQL1,cn);adap2=newOleDbDataAdapter(strSQL2,cn);dr1=cm1.ExecuteReader();dr2=cm2.ExecuteReader();intLsum;ArrayListPR=newArrayList();ArrayListPT=newArrayList();ArrayListP0R=newArrayList();ArrayListPsum=newArrayList();ArrayListPL=newArrayList();ArrayListPTA=newArrayList();ArrayListP0=newArrayList();while(dr1.Read()){PR.Add(dr1["PR"]);PT.Add(dr1["PT"]);P0R.Add(dr1["P0"]);Psum.Add(dr1["Psum"]);}while(dr2.Read()){PL.Add(dr2["配线网损所占比例"]);PTA.Add(dr2["配变网损所占比例"]);P0.Add(dr2["配变空损所占比例"]);}Lsum=PR.Count;stringDataInsert;for(inti=0;i<Lsum;i++){PL[i]=double.Parse(PR[i].ToString())/double.Parse(Psum[i].ToString());PTA[i]=double.Parse(PT[i].ToString())/double.Parse(Psum[i].ToString());P0[i]=double.Parse(P0R[i].ToString())/double.Parse(Psum[i].ToString());DataInsert="updateAnalysisset"+"PL='"+PL[i]+"',PT='"+PTA[i]+"',P0="+P0[i];cm2=newOleDbCommand(DataInsert,cn);intAnalysisRowsNum=cm2.ExecuteNonQuery();}DataTabledt=newDataTable();adap2.Fill(dt);dataGridView1.DataSource=dt.DefaultView;dataGridView1.ColumnHeadersDefaultCellStyle.Font=newFont("宋体",11);dataGridView1.ScrollBars=ScrollBars.Both;dataGridView1.CellBorderStyle=DataGridViewCellBorderStyle.Single;cn.Close();
解决方案
本帖最后由 VisualEleven 于 2015-06-02 17:02:31 编辑