Dim Result As DialogResult
Result = Messagebox.Show("是否确认导入到" & e.fORm.Controls("combobox1").value & "考试成绩表中","警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
If Result = DialogResult.YES Then
Dim dlg As new OpenFileDialog
dlg.Filter = "Excel|*.xls;*.xlsx"
Dim ksmc As String = trim(e.Form.controls("combobox1").value)
Dim cmd As new SQLCommand
cmd.C
cmd.CommandText = "Sele ct * from{成绩} where 考试名称 = '" & ksmc & "'"
Dim dt As DataTable = cmd.ExecuteReader(True)
If dlg.ShowDialog = DialogResult.OK Then
Dim Book As New XLS.Book(dlg.FileName)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Dim str As String = trim(e.Form.controls("combobox1").value)
If sheet(0,0).value.Contains(str) Then
For n As Integer = 2 To Sheet.Rows.Count -1
Dim dr As DataRow = dt.find("考试名称 = '" & ksmc & "' and 考号 = '" & trim(sheet(n,0).value) & "'")
If dr IsNot Nothing Then
For m As Integer = 1 To sheet.Cols.count -1
dr(trim(sheet(1,m).value) & "_B") = val(sheet(n,m).value)
Next
End If
Next
dt.save
End If
DataTables("成绩").load
Else
Messagebox.Show("你所选择的EXCL表第一行不包含考试名称,有可能你选错了表或选错了考试名称","警告")
End If
End If
老师我设计时为了防止用户选表时出现选错样表,但测试mess不出现呢?