473,725 Members | 2,271 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Importing csv files must have a csv extension?

Hi,

I'm importing some csv files with this code

/// start of code snippet
int iPos = strFileName.Las tIndexOf(@"\");

string strPath = strFileName.Sub string(0,iPos);
string strSelect = "Select * from [" + strFileName.Sub string(iPos+1) + "]";

string strConnection;
strConnection = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=";

strConnection += strPath;
strConnection += ";Extended Properties='tex t;HDR=No;FMT=De limited'";

System.Data.Ole Db.OleDbConnect ion CSVConnection = new
System.Data.Ole Db.OleDbConnect ion(strConnecti on);
CSVConnection.O pen();

System.Data.Ole Db.OleDbDataAda pter CSVAdapter = new
System.Data.Ole Db.OleDbDataAda pter(strSelect, CSVConnection);

DataSet CSVDataset = new DataSet("CSVFil e");

CSVAdapter.Fill (CSVDataset, "CSVFile");

CSVConnection.C lose();

DataTable CSVDatatable;
CSVDatatable = CSVDataset.Tabl es["CSVFile"];

/// end of code snippet

I have found that only files with a .csv extension can be opened otherwise I
get an exception that read 'Cannot Update, Database or Object is read-only'.
Is that normal and is there a way around it?

Also, since I'm using the Microsoft.Jet.O LEDB.4.0 provider will the users
machine need to have Access or Office installed in order for this to work?

Finally, should I be using another provider, just wondering since I took
most of it from a sample code.

Thank you for your time.

Nov 16 '05 #1
3 2618
James,

I don't know of any limitation that prevents you from using a text file
with an extension other than csv, but I can't say without a doubt that this
isn't a limitation.

You might want to try the text driver with the classes in
System.Data.Odb c, it might provide a better experience for you.

I believe the connection string would be something like this:
Driver={Microso ft Text Driver (*.txt;
*.csv)};Dbq=c:\ somepath\;Exten sions=asc,csv,t ab,txt;Persist Security
Info=False;

Note you can set the extensions in the connection string.

You won't be required to have Access installed to run Jet, you just have
to have the support files for the Jet provider, should you choose to use it.
It's just that Access typically installs this.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"James" <j@j.net> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hi,

I'm importing some csv files with this code

/// start of code snippet
int iPos = strFileName.Las tIndexOf(@"\");

string strPath = strFileName.Sub string(0,iPos);
string strSelect = "Select * from [" + strFileName.Sub string(iPos+1) +
"]";

string strConnection;
strConnection = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=";

strConnection += strPath;
strConnection += ";Extended Properties='tex t;HDR=No;FMT=De limited'";

System.Data.Ole Db.OleDbConnect ion CSVConnection = new
System.Data.Ole Db.OleDbConnect ion(strConnecti on);
CSVConnection.O pen();

System.Data.Ole Db.OleDbDataAda pter CSVAdapter = new
System.Data.Ole Db.OleDbDataAda pter(strSelect, CSVConnection);

DataSet CSVDataset = new DataSet("CSVFil e");

CSVAdapter.Fill (CSVDataset, "CSVFile");

CSVConnection.C lose();

DataTable CSVDatatable;
CSVDatatable = CSVDataset.Tabl es["CSVFile"];

/// end of code snippet

I have found that only files with a .csv extension can be opened otherwise
I
get an exception that read 'Cannot Update, Database or Object is
read-only'.
Is that normal and is there a way around it?

Also, since I'm using the Microsoft.Jet.O LEDB.4.0 provider will the users
machine need to have Access or Office installed in order for this to work?

Finally, should I be using another provider, just wondering since I took
most of it from a sample code.

Thank you for your time.

Nov 16 '05 #2
Hi,

Take a look at the opennetcf.org csv's provider. It does works great and you
have the source code too !

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"James" <j@j.net> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hi,

I'm importing some csv files with this code

/// start of code snippet
int iPos = strFileName.Las tIndexOf(@"\");

string strPath = strFileName.Sub string(0,iPos);
string strSelect = "Select * from [" + strFileName.Sub string(iPos+1) + "]";
string strConnection;
strConnection = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=";

strConnection += strPath;
strConnection += ";Extended Properties='tex t;HDR=No;FMT=De limited'";

System.Data.Ole Db.OleDbConnect ion CSVConnection = new
System.Data.Ole Db.OleDbConnect ion(strConnecti on);
CSVConnection.O pen();

System.Data.Ole Db.OleDbDataAda pter CSVAdapter = new
System.Data.Ole Db.OleDbDataAda pter(strSelect, CSVConnection);

DataSet CSVDataset = new DataSet("CSVFil e");

CSVAdapter.Fill (CSVDataset, "CSVFile");

CSVConnection.C lose();

DataTable CSVDatatable;
CSVDatatable = CSVDataset.Tabl es["CSVFile"];

/// end of code snippet

I have found that only files with a .csv extension can be opened otherwise I get an exception that read 'Cannot Update, Database or Object is read-only'. Is that normal and is there a way around it?

Also, since I'm using the Microsoft.Jet.O LEDB.4.0 provider will the users
machine need to have Access or Office installed in order for this to work?

Finally, should I be using another provider, just wondering since I took
most of it from a sample code.

Thank you for your time.

Nov 16 '05 #3
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
James,

I don't know of any limitation that prevents you from using a text file with an extension other than csv, but I can't say without a doubt that this isn't a limitation.

You might want to try the text driver with the classes in
System.Data.Odb c, it might provide a better experience for you.

I believe the connection string would be something like this:
Driver={Microso ft Text Driver (*.txt;
*.csv)};Dbq=c:\ somepath\;Exten sions=asc,csv,t ab,txt;Persist Security
Info=False;

Note you can set the extensions in the connection string.

You won't be required to have Access installed to run Jet, you just have to have the support files for the Jet provider, should you choose to use it. It's just that Access typically installs this.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m


Thanks for your help.

I tried it but started getting the 'data source name not found' error which
was like a scary flashback to my DAO days. I tried a few variations but I
think I'll stick to the Jet for a while.

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1405
by: Ed Leafe | last post by:
If I have a Python script in a file named "burp.zz", is there any way to import it into another script as you can with files named with the ..py extension? I looked at the imp module, but was not able to make it do what I wanted. Is this possible, or is the py/pyc extension required? ___/ / __/
0
1371
by: Mark English | last post by:
Basic problem: If there is a C-extension module in a package and it tries to import another python module in the same package without using the fully qualified path, the import fails. Config: Python 2.4 on Windows 2000 For example: mypackage contains:
4
4061
by: Glen | last post by:
I presently use the following code to import an Excel Spreadsheet: DoCmd.TransferSpreadsheet acImport, SpreadsheetType:=8, _ TableName:="tblImportPlayerInformation", _ FileName:="C:\PlayerInformation\ExportPlayerInformation.xls", _ Hasfieldnames:=True Is there a way to not have the speadsheet name defined in code but to go a specific directory and select a speadsheet to import. I import the full contents of the spreadsheet and no...
2
2117
by: steve | last post by:
Hello, I am trying to import an image file into a form. This would be a persons picture saved in the same directory for every unique record. I don't have any problems making an action button to open the directory where the images are but I am having problems putting the images in the form and also linking a field in a table to this image. I would rather not have the images saved in access2000 but simple linked to the file in the directory...
3
2598
by: Phil | last post by:
Hi, I am a novice user so please be gentle.;-) I am trying to import a very large CSV file with an extension of .DRF Access wont let me import it because DRF is not one of the extensions recognized under text files. I assume I need to write a Schema.ini to do this but I can't find any examples that would help in this situation. Could somebody point me in the right direction? Thanks Phil
29
4221
by: Natan | last post by:
When you create and aspx page, this is generated by default: using System; using System.Collections; using System.Collections.Specialized; using System.Configuration; using System.Text; using System.Text.RegularExpressions; using System.Web; using System.Web.Caching;
4
2214
by: Kathie via AccessMonster.com | last post by:
Hello, I have to import monthly, files that were once *.csv but due to commas in addresses, the interface program was changed to dump tab delimited. Now my code is not finding the files in the folder? The code is below - can anyone help? (The files still are named with the extension of *.csv) Function Import_Records() 'On Error GoTo Import_Records_Err 'Delete the all records in MONTHLY_IMPORTS table 'Call...
1
3881
by: Toby | last post by:
Hi, I've managed to get my hands on the ms 2003 toolkit, and have successfully (i think) created a .pyd file in win xp (setup.py is provided intersystems cache): -------------------------------------------------------------------- C:\CacheSys\Dev\python>setup.py install enter directory where you installed Cache'c:\CacheSys libdir=c:\CacheSys\dev\cpp\lib include dir=c:\CacheSys\dev\cpp\include running install
1
2261
by: gollumullog | last post by:
Good Day, I have been having this issue for quite a long time, and have yet to find an easy/elegant solution. I am trying to create tables in an Access database. I have these tables as CSV files, with the Header as the first line. I have approximately 1000 tables.
0
8889
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9179
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9116
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.