日期:2014-05-16  浏览次数:20376 次

将数据库一张表中多个field中的内容转移到field和值对应的表中
  


       
Data_basic recordData = new Data_basic();
        Data_basic recordData2 = new Data_basic();
        recordData.ExecuteDataset(string.Format("select staffID,unitLeader,drawing,teaching,computer from igos_Staff"));
        DataTable dt = new DataTable();
        DataRow rowEdited = dt.NewRow();
        if (recordData.AffectedRow > 0)
        {
            for (int y = 0; y < recordData.Dataset.Tables.Count; y++)
            {
                dt = recordData.Dataset.Tables[y];
                for (int x = 0; x < recordData.Dataset.Tables[y].Rows.Count; x++)
                {
                    rowEdited = dt.Rows[x];
                    string s = (String.Format(@"insert into igos_StaffType 
                                      (staffID, items, itemValue) values (
                                      '{0}','{1}','{2}')",
                                          rowEdited["staffID"], "unitLeader", rowEdited["unitLeader"]));
                    s += (String.Format(@"insert into igos_StaffType 
                                      (staffID, items, itemValue) values (
                                      '{0}','{1}','{2}')",
                                          rowEdited["staffID"], "drawing", rowEdited["drawing"]));
                    s += (String.Format(@"insert into igos_StaffType 
                                      (staffID, items, itemValue) values (
                                      '{0}','{1}','{2}')",
                                         rowEdited["staffID"], "teaching", rowEdited["teaching"]));
                    s += (String.Format(@"insert into igos_StaffType 
                                      (staffID, items, itemValue) values (
                                      '{0}','{1}','{2}')",
                                       rowEdited["staffID"], "computer", rowEdited["computer"]));
                    recordData2.ExcuteNonQuery(s);
                }
            }
        }