Esempio n. 1
0
        private void seekExcel(string Name, DataTable dt, Recordset recordset, int m)
        {
            //Hashtable h1 = new Hashtable();//存储乡镇和GDP
            //Hashtable h2 = new Hashtable();//存储乡镇和人口
            //Hashtable h3 = new Hashtable();//存储乡镇和耕地面积
            bool next = false;
            try
            {
                //循环查找 乡镇和GDP装入h1中
                for (int seekXZ = 0; seekXZ < dt.Rows.Count; seekXZ++)
                {
                    for (int seekColumn = 0; seekColumn < dt.Columns.Count; seekColumn++)
                    {
                        string s = dt.Rows[seekXZ][seekColumn].ToString();
                        if (s == Name)
                        {
                            
                            double valueGDP = Convert.ToDouble(dt.Rows[seekXZ][seekColumn + 1]);
                            double valueAC = Convert.ToDouble(dt.Rows[seekXZ][seekColumn + 2]);
                            double valuePE = Convert.ToDouble(dt.Rows[seekXZ][seekColumn + 3]);
                            recordset.SeekID(m);
                            recordset.Edit();
                            recordset.SetDouble("生产总值", valueGDP);
                            recordset.Update();
                            recordset.SeekID(m);
                            recordset.Edit();
                            recordset.SetDouble("耕地面积", valueAC);
                            recordset.Update();
                            recordset.SeekID(m);
                            recordset.Edit();
                            recordset.SetDouble("人口总数", valuePE);
                            recordset.Update();
                            recordset.Refresh();
                            next = true;
                            break;
                        }
                        if (next)
                            break;
                    }
                    if (next)
                        break;
                }
                /*MessageBox.Show(valueGDP.ToString() + recordset.GetObject("GDP").ToString());

                            //continue;
                            for (int r = 0; r < dt.Rows.Count; r++)
                            {
                                string n = dt.Rows[r][seekColumn].ToString();
                                if (dt.Rows[r][seekColumn].ToString() == Name)
                                {
                                    for (int recircle = 0; recircle < dt.Columns.Count; recircle++)
                                    {
                                        if (dt.Columns[recircle].ColumnName == "生产总值")
                                        {
                                            recordset.SeekID(m);
                                            recordset.Edit();
                                            object valueGDP = dt.Rows[r][recircle];
                                            recordset.SetFieldValue("GDP", valueGDP);
                                            recordset.Update();
                                            MessageBox.Show(valueGDP.ToString() + recordset.GetObject("GDP").ToString());

                                        }
                                        else
                                            if (dt.Columns[recircle].ColumnName == "耕地面积")
                                            {
                                                recordset.SeekID(m);
                                                recordset.Edit();
                                                object valueAC = dt.Rows[r][recircle];
                                                recordset.SetFieldValue("耕地面积", valueAC);
                                                recordset.Update();

                                                MessageBox.Show(valueAC.ToString() + recordset.GetObject("耕地面积").ToString());

                                            }
                                            else if (dt.Columns[recircle].ColumnName == "人口总数")
                                            {
                                                recordset.SeekID(m);
                                                recordset.Edit();
                                                object valuePE = dt.Rows[r][recircle];
                                                recordset.SetFieldValue("总人口", valuePE);
                                                recordset.Update();
                                                MessageBox.Show(valuePE.ToString() + recordset.GetObject("总人口").ToString());

                                            }
                                            else
                                                continue;
                                    }
                                }
                            }

                        }*/


                //for (int i = 0; i < dt.Columns.Count; i++)
                //{
                //    if (dt.Columns[i].ColumnName == "乡镇名称")
                //    {

                //    }
                //}
                //}

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }