以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 后台查找 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=92623) |
-- 作者:刘林 -- 发布时间:2016/11/8 20:10:00 -- 后台查找 Dim com4 As String = e.Form.Controls("combobox4").text If com4 > "" Dim Cols1() As String = {"学校名称","年级","班级","学生姓名","学生ID","学校标识码"} Dim Cols2() As String = {"单位名称","年级代码","班级","姓名","学生ID","学校代码"} Dim su As Integer = 0 Dim dr2 As DataRow For Each dr1 As DataRow In DataTables("学生信息").DataRows dr2 = DataTables("成绩").Find("学生ID = \'" & dr1("学生ID") & "\' and 考试名称 = \'" & com4 & "\'") If dr2 Is Nothing Then dr2 = DataTables("成绩").AddNew() For i As Integer = 0 To Cols1.Length -1 Select Case i Case 0 dr2(Cols2(i)) = dr1(Cols1(i)) Case 1 dr2(Cols2(i)) = dr1(Cols1(i)).Substring(4,2) Case 2 Dim c() As Char = {"级", "班"} Dim str As String = dr1(Cols1(i)) Dim s1() As String = str.Split(c) dr2(Cols2(i)) = s1(1).PadLeft(2,"0") Case 3 dr2(Cols2(i)) = dr1(Cols1(i)) Case 4 dr2(Cols2(i)) = dr1(Cols1(i)) Case 5 dr2(Cols2(i)) = trim(dr1(Cols1(i))).Substring(6,4) End Select Next dr2("考试名称") = com4 su = su +1 Next Dim sux As String = "本次共导入学生" & su & "人" MessageBox.show(sux,"导入总计",MessageBoxButtons.OK) 为防止重复增加相同记录,对同一次考试一个学生ID只能增加一次,上面代码仅当相同记录加载时可行,但重启系统因初始为不加载,这时可再增加相同记录,请问怎么办? |
-- 作者:有点蓝 -- 发布时间:2016/11/8 20:14:00 -- sqlfind:http://www.foxtable.com/webhelp/scr/2911.htm dr2 = DataTables("成绩").SQLFind("学生ID = \'" & dr1("学生ID") & "\' and 考试名称 = \'" & com4 & "\'")
|
-- 作者:刘林 -- 发布时间:2016/11/8 20:20:00 -- 我之前试过,这样可连续加相同记录,如果用find还好,至少不能连续增加,是什么样原因 |
-- 作者:有点蓝 -- 发布时间:2016/11/8 20:30:00 -- 只能是每增加一行就保存一下,不然后台是查不到的 Dim com4 As String = e.Form.Controls("combobox4").text If com4 > "" Dim Cols1() As String = {"学校名称","年级","班级","学生姓名","学生ID","学校标识码"} Dim Cols2() As String = {"单位名称","年级代码","班级","姓名","学生ID","学校代码"} Dim su As Integer = 0 Dim dr2 As DataRow For Each dr1 As DataRow In DataTables("学生信息").DataRows dr2 = DataTables("成绩").sqlFind("学生ID = \'" & dr1("学生ID") & "\' and 考试名称 = \'" & com4 & "\'") If dr2 Is Nothing Then dr2 = DataTables("成绩").AddNew() For i As Integer = 0 To Cols1.Length -1 Select Case i Case 0 dr2(Cols2(i)) = dr1(Cols1(i)) Case 1 dr2(Cols2(i)) = dr1(Cols1(i)).Substring(4,2) Case 2 Dim c() As Char = {"级", "班"} Dim str As String = dr1(Cols1(i)) Dim s1() As String = str.Split(c) dr2(Cols2(i)) = s1(1).PadLeft(2,"0") Case 3 dr2(Cols2(i)) = dr1(Cols1(i)) Case 4 dr2(Cols2(i)) = dr1(Cols1(i)) Case 5 dr2(Cols2(i)) = trim(dr1(Cols1(i))).Substring(6,4) End Select Next dr2("考试名称") = com4 su = su +1 dr2.Save Next Dim sux As String = "本次共导入学生" & su & "人" MessageBox.show(sux,"导入总计",MessageBoxButtons.OK) |
-- 作者:刘林 -- 发布时间:2016/11/8 20:39:00 -- 哦对了,谢谢 |