16,553
社区成员
发帖
与我相关
我的任务
分享
Dim fileName As String
fileName = Me.OpenFileDialog1.FileName
'建立EXCEL连接,读入数据
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & fileName & "';Extended Properties=Excel 8.0;"
'Dim myDataset As New DataSet
Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn)
Dim mydataset As DataSet = New DataSet
Try
da.Fill(mydataset)
Me.DataGridView1.DataSource = mydataset.Tables(0)
Catch ex As Exception
End Try
If mydataset.Tables(0).Rows.Count > 0 Then
Dim strSql As String '////////////// imports///////////////
Dim CnnStr As String = "server=localhost;database=AAA;user id=sa;password=AAA"
Dim conn As SqlClient.SqlConnection = New SqlConnection(CnnStr)
conn.Open()
Dim myCmd As SqlCommand
Dim i As Integer
For i = 0 To mydataset.Tables(0).Rows.Count - 1 Step i + 1
strSql = "Insert Into ......"
Try
myCmd = New SqlCommand(strSql, conn)
myCmd.ExecuteNonQuery()
Catch
End Try
Next
MsgBox("导入保存成功!")
End If
End If
Dim fileName As String