-- 作者:zgjmost
-- 发布时间:2015/6/12 10:43:00
-- 时间导入问题
我要把排好了的机考导入到数据库中
由于XLS表中的时间格式导入是下面这个情况
此主题相关图片如下:qq截图20150612103750.png
所有我写了一段代码
如下:
Dim Valuessj() As String Dim rq2,rq3,rq4 As String Valuessj = rq1.split("/") rq2 = Valuessj(0) If Valuessj(1).Length = 1 Then rq3 = "0" & Valuessj(1) Else rq3 = Valuessj(1) End If If Valuessj(2).Length = 1 Then rq4 = "0" & Valuessj(2) Else rq4 = Valuessj(2) End If rq = rq2 & "-" & rq3 & "-" & rq4
但报错,请专家指点!
实例如下:
点实例中的机考导入,XLS表在压缩包中!
谢谢!
|
-- 作者:大红袍
-- 发布时间:2015/6/12 11:24:00
--
无语,你做的例子根本就没有问题,根本就不需要处理。
Forms("主界面").Open() MainTable = Tables("主界面")
Dim dlg As new OpenFileDialog dlg.Filter= "Excel文件|*.xls" If dlg.ShowDialog = DialogResult.Ok Then Dim xh,sjh,rq1,rq,sj,js,zwh As String application.DoEvents Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) StatusBar.Message1= "正在导入数据,请稍候" StatusBar.ProgressBar.Maximum = sheet.Rows.Count StatusBar.ProgressBar.Minimum = 0 StatusBar.ProgressBar.Visible =True application.DoEvents If sheet(0,0).text <> "机考安排表" Or sheet(2,0).text <> "姓名" Or sheet(2,1).text <> "学号" Or sheet(2,2).text <> "试卷号" Or sheet(2,3).text <> "试卷名称" Then MessageBox.Show("您的数据源不符合国家开放大学报表平台的数据格式,不能导入学生信息表数据!", "提示") Else DataTables("考试数据表").StopRedraw For i As Integer = 3 To sheet.Rows.Count -1 xh = sheet(i,1).text sjh = sheet(i,2).text rq = sheet(i,6).text sj = sheet(i,7).text js = sheet(i,8).text zwh = sheet(i,9).text Dim dr As DataRow = DataTables("考试数据表").find("学号 = \'" & xh & "\' and 试卷号 = \'" & sjh & "\'") If dr IsNot Nothing Then dr("日期") = rq dr("时间") = sj dr("教室") = js If zwh <> "" Then dr("座位号") = CInt(zwh) End If End If
StatusBar.ProgressBar.Value = i StatusBar.Message2= Math.Ceiling(i/sheet.Rows.Count * 100) & "%" application.DoEvents Next DataTables("考试数据表").ResumeRedraw End If End If
With Tables("考试数据表") For i As Integer = 0 To .Rows.Count - 1 .Rows(i)("起始时间") = Left(.Rows(i)("时间"),5) .Rows(i)("结束时间") = Right(.Rows(i)("时间"),5) .Rows(i)("短日期") = Right(.Rows(i)("日期"),2) & "日" Next End With
For Each r As Row In Tables("考试数据表").Rows Dim st As String = r("起始时间") If st.EndsWith("-") Then r("起始时间") = "0" & r("起始时间").trim("-") End If Next
MessageBox.Show("祝贺你!机考数据导入成功!") StatusBar.Reset()
|
-- 作者:zgjmost
-- 发布时间:2015/6/12 11:32:00
--
Forms("主界面").Open() MainTable = Tables("主界面")
Dim dlg As new OpenFileDialog dlg.Filter= "Excel文件|*.xls" If dlg.ShowDialog = DialogResult.Ok Then Dim xh,sjh,rq1,rq,sj,js,zwh As String application.DoEvents Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) StatusBar.Message1= "正在导入数据,请稍候" StatusBar.ProgressBar.Maximum = sheet.Rows.Count StatusBar.ProgressBar.Minimum = 0 StatusBar.ProgressBar.Visible =True application.DoEvents If sheet(0,0).text <> "机考安排表" Or sheet(2,0).text <> "姓名" Or sheet(2,1).text <> "学号" Or sheet(2,2).text <> "试卷号" Or sheet(2,3).text <> "试卷名称" Then MessageBox.Show("您的数据源不符合国家开放大学报表平台的数据格式,不能导入学生信息表数据!", "提示") Else DataTables("选课数据表").StopRedraw For i As Integer = 3 To sheet.Rows.Count -1 xh = sheet(i,1).text sjh = sheet(i,2).text rq1 = sheet(i,6).text sj = sheet(i,7).text js = sheet(i,8).text zwh = sheet(i,9).text Dim Valuessj() As String Dim rq2,rq3,rq4 As String Valuessj = rq1.split("/") rq2 = Valuessj(0) If Valuessj(1).Length = 1 Then rq3 = "0" & Valuessj(1) Else rq3 = Valuessj(1) End If If Valuessj(2).Length = 1 Then rq4 = "0" & Valuessj(2) Else rq4 = Valuessj(2) End If rq = rq2 & "-" & rq3 & "-" & rq4 Dim dr As DataRow = DataTables("选课数据表").find("学号 = \'" & xh & "\' and 试卷号 = \'" & sjh & "\'") If dr IsNot Nothing Then dr("日期") = rq dr("时间") = sj dr("教室") = js If zwh <> "" Then dr("座位号") = CInt(zwh) End If End If StatusBar.ProgressBar.Value = i StatusBar.Message2= Math.Ceiling(i/sheet.Rows.Count * 100) & "%" application.DoEvents Next DataTables("选课数据表").ResumeRedraw End If End If
With Tables("选课数据表") For i As Integer = 0 To .Rows.Count - 1 .Rows(i)("起始时间") = Left(.Rows(i)("时间"),5) .Rows(i)("结束时间") = Right(.Rows(i)("时间"),5) .Rows(i)("短日期") = Right(.Rows(i)("日期"),2) & "日" Next End With
For Each r As Row In Tables("选课数据表").Rows Dim st As String = r("起始时间") If st.EndsWith("-") Then r("起始时间") = "0" & r("起始时间").trim("-") End If Next
MessageBox.Show("祝贺你!机考数据导入成功!") StatusBar.Reset()
这是我的机考导入的代码
报错是这样的
此主题相关图片如下:qq截图20150612112743.png
想解决下面日期格式不一到,
此主题相关图片如下:qq截图20150612103750.png
导致后面用目录树的情况出现下列的错误情况。
此主题相关图片如下:qq截图20150612112504.png
|