如何使用vb.net将excel数据导入到Windows应用程序中的MS访问数据库 [英] How to import the excel data to MS access database in windows application using vb.net

查看:71
本文介绍了如何使用vb.net将excel数据导入到Windows应用程序中的MS访问数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,我对MS访问数据库有要求。使用vb.net将excel数据导入ms访问数据库。这对我来说是新的要求。请任何人帮助我.....



Dim Access As String =C:\ Users\grva3242\Desktop\guru.mdb< br $>


Dim Excel As String =C:\ Users\grva3242\Desktop\NLRMP\RSR.XLS

' Dim connect As String =Provider = Microsoft.Jet.OLEDB.4.0; Data Source =& Excel& ;扩展属性= Excel 8.0;



Dim connect As String =Provider = Microsoft.ACE.OLEDB.12.0; Data Source =+ Excel +;扩展属性=Excel 12.0 Xml; HRD = NO





使用conn作为新的OleDbConnection(连接)

使用cmd作为新的OleDbCommand()

cmd.Connection = conn

cmd.CommandText =INSERT INTO [MS Access; Database =&访问& ]。[村] SELECT * FROM [Sheet1 $]

conn.Open()

cmd.ExecuteNonQuery()

结束使用

结束使用





hi friends , I have requirement on MS access Database. importing the excel data to ms access database using vb.net . this is new requirement for me. Please any one help me.....

Dim Access As String = "C:\Users\grva3242\Desktop\guru.mdb"

Dim Excel As String = "C:\Users\grva3242\Desktop\NLRMP\RSR.XLS"
' Dim connect As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Excel & ";Extended Properties=Excel 8.0;"

Dim connect As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Excel + ";Extended Properties=""Excel 12.0 Xml;HRD=NO"""


Using conn As New OleDbConnection(connect)
Using cmd As New OleDbCommand()
cmd.Connection = conn
cmd.CommandText = "INSERT INTO [MS Access;Database=" & Access & "].[village] SELECT * FROM [Sheet1$]"
conn.Open()
cmd.ExecuteNonQuery()
End Using
End Using


Here village is empty table in guru database.

I got the error is :<b>Could not find file 'C:\Users\grva3242\Desktop\guru.mdb'.</b>

推荐答案



conn.Open()

cmd.ExecuteNonQuery()

结束使用

结束使用





"
conn.Open()
cmd.ExecuteNonQuery()
End Using
End Using


Here village is empty table in guru database.

I got the error is :<b>Could not find file 'C:\Users\grva3242\Desktop\guru.mdb'.</b>


http://social.msdn.microsoft.com/Forums/en-US/ba1f1926-3524-4375-8812-3ff300293b12/import-excel-sheet-to-access- database-using-vbnet [ ^ ]



http://www.vbforums.com/showthread.php?675506-RESOLVED-Import -from-Excel-into-existing-Access-table [ ^ ]


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

     Dim fln As String = "D:\flName.xls"

     Dim conn As String

     conn = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & fln & ";" & "Extended Properties=Excel 8.0;"

     Dim con As OleDbConnection = New OleDbConnection(conn)

     Dim da As OleDbDataAdapter = New OleDbDataAdapter()

     Dim cmd As OleDbCommand = New OleDbCommand()

     cmd.Connection = con 

     cmd .CommandText = "SELECT * FROM [Sheet1


这篇关于如何使用vb.net将excel数据导入到Windows应用程序中的MS访问数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆