ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Import csv file into excel programmatically (https://www.excelbanter.com/excel-programming/321174-import-csv-file-into-excel-programmatically.html)

Saumin

Import csv file into excel programmatically
 
hi,
I want to import a csv file into my excel template file programmatically in
a windows application. i am using vb.net, ado.net to do this. but i am
getting an error: Operation must use an updateable query. I have checked
security and it is fine. aspnet user has full permissions on both the files.
I will really appreciate a quick response. following is the code:
csvPath = "c:\"
strCSVConn = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Da ta
Source={0};Extended Properties=""text;HDR=No;FMT=Delimited""", csvPath)

Dim objCSVConn As New OleDbConnection(strCSVConn)
objCSVConn.Open()
Dim objCmd As New OleDbCommand
objCmd.Connection = objCSVConn
Try
objCmd.CommandText = "Insert INTO [Sheet1$] IN 'C:\Book1.xls'
'Excel 8.0;' SELECT * FROM 261_WildOats_12292004_EE.csv"
objCmd.ExecuteNonQuery()
objCSVConn.Close()
Catch ex As Exception
If Not (objCSVConn Is Nothing) Then
objCSVConn.Close()
End If
MsgBox(ex.Message)
End Try

Thanks,
Saumin


Jamie Collins

Import csv file into excel programmatically
 

Saumin wrote:
hi,
I want to import a csv file into my excel template file

programmatically in
a windows application. i am using vb.net, ado.net to do this. but i

am
getting an error: Operation must use an updateable query. I have

checked
security and it is fine. aspnet user has full permissions on both the

files.
I will really appreciate a quick response. following is the code:
csvPath = "c:\"
strCSVConn = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Da ta
Source={0};Extended Properties=""text;HDR=No;FMT=Delimited""",

csvPath)

Dim objCSVConn As New OleDbConnection(strCSVConn)
objCSVConn.Open()
Dim objCmd As New OleDbCommand
objCmd.Connection = objCSVConn
Try
objCmd.CommandText = "Insert INTO [Sheet1$] IN

'C:\Book1.xls'
'Excel 8.0;' SELECT * FROM 261_WildOats_12292004_EE.csv"
objCmd.ExecuteNonQuery()
objCSVConn.Close()
Catch ex As Exception
If Not (objCSVConn Is Nothing) Then
objCSVConn.Close()
End If
MsgBox(ex.Message)
End Try

Thanks,
Saumin



Saumin wrote:
hi,
I want to import a csv file into my excel template file

programmatically in
a windows application. i am using vb.net, ado.net to do this. but i

am
getting an error: Operation must use an updateable query. I have

checked
security and it is fine. aspnet user has full permissions on both the

files.
I will really appreciate a quick response. following is the code:
csvPath = "c:\"
strCSVConn = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Da ta
Source={0};Extended Properties=""text;HDR=No;FMT=Delimited""",

csvPath)

Dim objCSVConn As New OleDbConnection(strCSVConn)
objCSVConn.Open()
Dim objCmd As New OleDbCommand
objCmd.Connection = objCSVConn
Try
objCmd.CommandText = "Insert INTO [Sheet1$] IN

'C:\Book1.xls'
'Excel 8.0;' SELECT * FROM 261_WildOats_12292004_EE.csv"
objCmd.ExecuteNonQuery()
objCSVConn.Close()
Catch ex As Exception
If Not (objCSVConn Is Nothing) Then
objCSVConn.Close()
End If
MsgBox(ex.Message)
End Try


When using Text in the extended properties, the provider does not seem
to support the IN <database syntax. Try doing the other way round i.e.
use Excel 8.0 in the ADO connection string and Text in the IN clause.
Jamie.

--



All times are GMT +1. The time now is 05:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com