以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]关于行列转换效率的问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=47500) |
-- 作者:cat88hzh -- 发布时间:2014/3/11 16:47:00 -- [求助]关于行列转换效率的问题 各位大虾,我有一段这样的代码把12个月的表数据行列转换到另一个表的两个月份和数据字段中 For Each dr1 As DataRow In DataTables("GL_Budget_Definition").DataRows For m As Integer = 1 To 12 Dim dr As DataRow = DataTables("HZH_GL_ALL_BUDGET").AddNew Select Case m Case 1 dr("BUDGET_NO") = dr1("Budget_no") dr("DESCRIPTION") = dr1("Description") dr("DEPT") = dr1("Dept") dr("YEAR") = dr1("Year") dr("VERSION") = dr1("Version") dr("MONTH") = "Jan" ’其它都一样就这两句不同的 dr("AMONTS") = dr1("Jan") Case 2 dr("BUDGET_NO") = dr1("Budget_no") dr("DESCRIPTION") = dr1("Description") dr("DEPT") = dr1("Dept") dr("YEAR") = dr1("Year") dr("VERSION") = dr1("Version") dr("MONTH") = "Feb" dr("AMONTS") = dr1("Feb") Case 3 dr("BUDGET_NO") = dr1("Budget_no") dr("DESCRIPTION") = dr1("Description") dr("DEPT") = dr1("Dept") dr("YEAR") = dr1("Year") dr("VERSION") = dr1("Version") dr("MONTH") = "Mar" dr("AMONTS") = dr1("Mar") Case 4 dr("BUDGET_NO") = dr1("Budget_no") dr("DESCRIPTION") = dr1("Description") dr("DEPT") = dr1("Dept") dr("YEAR") = dr1("Year") dr("VERSION") = dr1("Version") dr("MONTH") = "Apr" dr("AMONTS") = dr1("Apr") Case 5 dr("BUDGET_NO") = dr1("Budget_no") dr("DESCRIPTION") = dr1("Description") dr("DEPT") = dr1("Dept") dr("YEAR") = dr1("Year") dr("VERSION") = dr1("Version") dr("MONTH") = "May" dr("AMONTS") = dr1("May") Case 6 dr("BUDGET_NO") = dr1("Budget_no") dr("DESCRIPTION") = dr1("Description") dr("DEPT") = dr1("Dept") dr("YEAR") = dr1("Year") dr("VERSION") = dr1("Version") dr("MONTH") = "Jun" dr("AMONTS") = dr1("Jun") Case 7 dr("BUDGET_NO") = dr1("Budget_no") dr("DESCRIPTION") = dr1("Description") dr("DEPT") = dr1("Dept") dr("YEAR") = dr1("Year") dr("VERSION") = dr1("Version") dr("MONTH") = "Jul" dr("AMONTS") = dr1("Jul") Case 8 dr("BUDGET_NO") = dr1("Budget_no") dr("DESCRIPTION") = dr1("Description") dr("DEPT") = dr1("Dept") dr("YEAR") = dr1("Year") dr("VERSION") = dr1("Version") dr("MONTH") = "Aug" dr("AMONTS") = dr1("Aug") Case 9 dr("BUDGET_NO") = dr1("Budget_no") dr("DESCRIPTION") = dr1("Description") dr("DEPT") = dr1("Dept") dr("YEAR") = dr1("Year") dr("VERSION") = dr1("Version") dr("MONTH") = "Sep" dr("AMONTS") = dr1("Sep") Case 10 dr("BUDGET_NO") = dr1("Budget_no") dr("DESCRIPTION") = dr1("Description") dr("DEPT") = dr1("Dept") dr("YEAR") = dr1("Year") dr("VERSION") = dr1("Version") dr("MONTH") = "Oct" dr("AMONTS") = dr1("Oct") Case 11 dr("BUDGET_NO") = dr1("Budget_no") dr("DESCRIPTION") = dr1("Description") dr("DEPT") = dr1("Dept") dr("YEAR") = dr1("Year") dr("VERSION") = dr1("Version") dr("MONTH") = "Nov" dr("AMONTS") = dr1("Nov") Case 12 dr("BUDGET_NO") = dr1("Budget_no") dr("DESCRIPTION") = dr1("Description") dr("DEPT") = dr1("Dept") dr("YEAR") = dr1("Year") dr("VERSION") = dr1("Version") dr("MONTH") = "Dec" dr("AMONTS") = dr1("Dec") End Select DataTables("HZH_GL_ALL_BUDGET").Load \'因为我是oracle数据库,用触发器做的主键ID,没插入一行才能触发一次ID,不然会报错,所以要加这一句同步的代码才行,感觉插入了900行要4秒钟,请问是否有高级的方法,可以价快速的? Next Next |
-- 作者:Bin -- 发布时间:2014/3/11 16:49:00 -- 呵呵,这个东西怎么弄效率都不会高. |
-- 作者:jspta -- 发布时间:2014/3/11 16:54:00 -- 你这个可以考虑用insert 语句 INSERT INTO table2(id, name, address) SELECT id, name, address FROM table1 DataTables("HZH_GL_ALL_BUDGET").Load 在循环体外 DataTables("HZH_GL_ALL_BUDGET").save不行吗? 还有代码太重复了,用数组简化下吧
|