16,721
社区成员




Dim mystring As String = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =" & Me.path.PostedFile.FileName & ";Extended Properties=Excel 8.0"
Dim cnnxls As New OleDbConnection(mystring)
Dim myDa As New OleDbDataAdapter("select * from [Sheet1$]", cnnxls)
Dim myDs As New DataSet
myDa.Fill(myDs)
If myDs.Tables(0).Rows.Count > 0 Then
Dim i As Integer = 0
Dim totalnum As Integer = 0
For i = 1 To myDs.Tables(0).Rows.Count
Dim con As String = "Password=bushuo;Persist Security Info=false;User ID=sa;Initial Catalog=qj;Data Source=localhost"
Dim conn As New Data.SqlClient.SqlConnection(con)
conn.Open()
Dim epeopleno As String = myDs.Tables(0).Rows(i).ItemArray(0)
Dim epeoplename As String = myDs.Tables(0).Rows(i).ItemArray(1)
Dim job As String = myDs.Tables(0).Rows(i).ItemArray(2)
Dim strSql = ("insert into pay(peopleno,peoplename,job) values (epeopleno,epeopelname,job)")
Try
Dim myCmd As New SqlCommand(strSql, conn)
myCmd.ExecuteNonQuery()
totalnum = totalnum + 1
Dim stra As String = "数据导入成功." + totalnum + " 条"
co.Alert(Page, "stra")
Catch ex As Exception
Response.Write("<script language=javascript>alert('数据导入失败.');</script>")
End Try
Next i
End If
For i = 1 To myDs.Tables(0).Rows.Count-1
epeopleno= myDs.Tables(0).Rows(i).Item(0)
epeoplename= myDs.Tables(0).Rows(i).Item(1)
job= myDs.Tables(0).Rows(i).Item(2)
strSql = ("insert into pay(peopleno,peoplename,job) values (" & epeopleno & ",'" & epeopelname & "','" & job & "')")
'Try
Dim myCmd As New SqlCommand(strSql, conn)
myCmd.ExecuteNonQuery()
totalnum = totalnum + 1
stra = "数据导入成功." + totalnum + " 条"
co.Alert(Page, stra)
'Catch ex As Exception
Response.Write("<script language=javascript>alert('数据导入失败.');</script>")
'End Try
Next
For i = 1 To myDs.Tables(0).Rows.Count
For i = 1 To myDs.Tables(0).Rows.Count - 1
Dim mystring As String = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =" & Me.path.PostedFile.FileName & ";Extended Properties=Excel 8.0"
Dim cnnxls As New OleDbConnection(mystring)
Dim myDa As New OleDbDataAdapter("select * from [Sheet1$]", cnnxls)
Dim myDs As New DataSet
myDa.Fill(myDs)
If myDs.Tables(0).Rows.Count > 0 Then
Dim i As Integer = 0
Dim totalnum As Integer = 0
Dim con As String = "Password=bushuo;Persist Security Info=false;User ID=sa;Initial Catalog=qj;Data Source=localhost"
Dim conn As New Data.SqlClient.SqlConnection(con)
conn.Open()
Dim epeopleno As String
Dim epeoplename As String
Dim job As String
Dim strSql As String
Dim stra As String
For i = 1 To myDs.Tables(0).Rows.Count-1
epeopleno= myDs.Tables(0).Rows(i).Item(0)
epeoplename= myDs.Tables(0).Rows(i).Item(1)
job= myDs.Tables(0).Rows(i).Item(2)
strSql = ("insert into pay(peopleno,peoplename,job) values (" & epeopleno & ",'" & epeopelname & "','" & job & "')")
Try
Dim myCmd As New SqlCommand(strSql, conn)
myCmd.ExecuteNonQuery()
totalnum = totalnum + 1
stra = "数据导入成功." + totalnum + " 条"
co.Alert(Page, stra)
Catch ex As Exception
Response.Write("<script language=javascript>alert('数据导入失败.');</script>")
End Try
Next i
conn.close()
End If
cnnxls.close()