VB怎麼用代码实现Excel导入SQL2000数据库

VB怎麼用代码实现Excel导入SQL2000数据库,例如我有个PMC.xls,裏面有字段cn_time、cn_date、cn_name,SQL有个PMC的表,裏面有字段cn_time、cn_date、cn_name;怎麼按一下Command1就把PMC.xls裏面的数据导入到数据库的表裏面。

CommonDialog1.Filter = "EXCEL文件(*.xls)|*.xls" CommonDialog1.ShowOpen filenamefet = CommonDialog1.FileName Text1.Text = filenamefet If Text1.Text = "" Then MsgBox "文件名不能为空", vbExclamation, "提示" Exit Sub End If Text2.Text = "sheet1" cn.CursorLocation = adUseClient cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & filenamefet & ";Extended Properties='Excel 8.0;HDR=Yes'" rs.Open "select * from [Sheet1$]", cn, adOpenDynamic, adLockOptimistic Set MSHFlexGrid1.DataSource = rs If rs.RecordCount > 0 Then Command2.Enabled = True Else Command2.Enabled = False End If rs.Close cn.Close Exit Sub

这是导入excel表到datagrid 控件,然后遍历整个datagrid控件,保存到SQL即可
温馨提示:答案为网友推荐,仅供参考