excel文件导入sql2000,碰到insert问题
vb.net吧
全部回复
仅看楼主
level 5
zgs0215 楼主
Imports System.Data.SqlClient
Public Class Form1
Dim myDataset As New DataSet
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim filename As String
Me.OpenFileDialog1.Filter = "Excle文件(*.xls)|*.xls"
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
filename = Me.OpenFileDialog1.FileName
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=*" & filename & "*;Extended Properties=*Excel 8.0;*"
*Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=*d:\qy.xls*;Extended Properties=*Excel 8.0;*"
Dim qy As New OleDb.OleDbDataAdapter("SELECT * FROM[sheet1$]", strConn)
*Dim myDataset As New DataSet
Try
qy.Fill(myDataset)
Me.DataGridView1.DataSource = myDataset.Tables(0)
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If myDataset.Tables(0).Rows.Count > 0 Then
Dim strSql As String
Dim CnnStr As String = "server=localhost;database=hz_tax;user id=sa;password=sa"
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 tbl_qyname ([id],[qy_name]) VALUES (*001*,*A*)"
strSql = "Insert Into tbl_qyname ([id],[nian],[yue],[qy_name]) VALUES (& id,*" & ComboBox1.Text & "*,*" & ComboBox2.Text & "*,& qy_name)"
--这里如何修改?
Try
myCmd = New SqlCommand(strSql, conn)
myCmd.ExecuteNonQuery()
Catch
End Try
Next
MsgBox("导入保存成功!")
End If
End Sub
End Class
2014年08月04日 15点08分 1
1