-- 作者:wsxdwh
-- 发布时间:2013/2/28 11:57:00
-- 现在想在导入前排序,代码如何修改?
以下是导入数据的代码,现在想在导入前排序,代码如何修改? 请指教!!!
要排序的表及行为:DataTables("" & xzb.Text & "").Select("竞赛名称 = \'"& jsmc.text &"\' and 参赛项目 = \'"& xm.text &"\' and 中小学 = \'" & zxx.Text & "\'")
排序的方法为:Tables(e.Form.Name & "_Table2").Sort)
Dim jsmc As WinForm.ComboBox = e.Form.Controls("竞赛名称") Dim xzb As WinForm.ComboBox = e.Form.Controls("选择表") Dim dt_jilu As DataTable = DataTables(""& xzb.text & "") Dim xm As WinForm.ComboBox = e.Form.Controls("项目") Dim dt_baoming As DataTable = DataTables("报名表") Dim dt_chengji As DataTable = DataTables("成绩表") Dim zxx As WinForm.ComboBox = e.Form.Controls("中小学1") Dim Ary As String() For Each Ary In dt_jilu .GetUniqueValues("竞赛名称 = \'"& jsmc.text &"\' and 中小学= \'" & zxx.text & "\' and 参赛项目 = \'"& xm.text &"\'","竞赛名称", "编号", "中小学", "学校", "姓名", "成绩1", "成绩2","奖项","时间排序") Dim flt As String = "编号 = \'" & ary(1) & "\' And 竞赛名称 = \'" & ary(0) & "\'" If dt_chengji.Find(flt) Is Nothing Then Dim ndr As DataRow = dt_chengji.AddNew ndr("竞赛名称") = ary(0) ndr("编号") = ary(1) ndr("中小学") = ary(2) ndr("学校") = ary(3) ndr("姓名") = ary(4) ndr("成绩1") = ary(5) ndr("成绩2") = ary(6) ndr("奖项") = ary(7) ndr("时间排序") = ary(8) Dim dr As DataRow = dt_baoming.Find("编号 = " & ary(1)) If dr IsNot Nothing Then ndr("区") = dr("区") ndr("参赛项目") = dr("参赛项目") ndr("辅导教师") = dr("辅导教师") End If End If Next End If
|
-- 作者:狐狸爸爸
-- 发布时间:2013/2/28 12:14:00
--
没有办法哦,只能导入后排序。
要不你导入到一个临时表中。
\'导入到临时表的代码
For each dr1 As DataRow in DataTables("临时表").Select("","排序字段")
Dim dr2 = DataTables("正是表").AddNew()
dr2("列1") = dr1("列1")
dr2("列2") = dr1("列2")
dr2("列3") = dr1("列3")
Next
[此贴子已经被作者于2013-2-28 12:16:52编辑过]
|
-- 作者:wsxdwh
-- 发布时间:2013/2/28 14:45:00
--
经测试 还是不行,成绩表被以编号为升序排序 ???
If MessageBox.Show("是否汇总到成绩表?","确认",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) =DialogResult.OK Then Dim jsmc As WinForm.ComboBox = e.Form.Controls("竞赛名称") Dim xzb As WinForm.ComboBox = e.Form.Controls("选择表") Dim dt_jilu As DataTable = DataTables(""& xzb.text & "") Dim xm As WinForm.ComboBox = e.Form.Controls("项目") Dim dt_baoming As DataTable = DataTables("报名表") Dim dt_chengji As DataTable = DataTables("成绩表") Dim zxx As WinForm.ComboBox = e.Form.Controls("中小学1") DataTables("临时成绩表").DataRows.Clear
For Each dr1 As DataRow In DataTables(""& xzb.text & "").Select("竞赛名称 = \'"& jsmc.text &"\' and 参赛项目 = \'"& xm.text &"\' and 中小学 = \'" & zxx.Text & "\'",Tables(e.Form.Name & "_Table2").Sort) Dim dr2 = DataTables("临时成绩表").AddNew() dr2("竞赛名称") = dr1("竞赛名称") dr2("编号") = dr1("编号") dr2("中小学") = dr1("中小学") dr2("学校") = dr1("学校") dr2("姓名") = dr1("姓名") dr2("成绩1") = dr1("成绩1") dr2("成绩2") = dr1("成绩2") dr2("奖项") = dr1("奖项") dr2("时间排序") = dr1("时间排序") Next Dim Ary As String() For Each Ary In DataTables("临时成绩表").GetUniqueValues("","竞赛名称", "编号", "中小学", "学校", "姓名", "成绩1", "成绩2","奖项","时间排序") Dim flt As String = "编号 = \'" & ary(1) & "\' And 竞赛名称 = \'" & ary(0) & "\'" If dt_chengji.Find(flt) Is Nothing Then Dim ndr As DataRow = dt_chengji.AddNew ndr("竞赛名称") = ary(0) ndr("编号") = ary(1) ndr("中小学") = ary(2) ndr("学校") = ary(3) ndr("姓名") = ary(4) ndr("成绩1") = ary(5) ndr("成绩2") = ary(6) ndr("奖项") = ary(7) ndr("时间排序") = ary(8) Dim dr As DataRow = dt_baoming.Find("编号 = " & ary(1)) If dr IsNot Nothing Then ndr("区") = dr("区") ndr("参赛项目") = dr("参赛项目") ndr("辅导教师") = dr("辅导教师") End If End If Next End If
DataTables("成绩表").Save() DataTables("成绩表").AllowEdit =False 此主题相关图片如下:ukpfveq5yu%p5el)aiqh41.jpg
此主题相关图片如下:p90jp~@3ap`ltqishh70wh.jpg
|