PC Review


Reply
Thread Tools Rate Thread

ADO.Net, Jet, and Text Files

 
 
Bill Pierce
Guest
Posts: n/a
 
      1st Aug 2003
I need some help/verificaion of my problem. The code below works just fine.
Data is read from a text file using the OLE DB Jet provider, parsed, and
then imported into another database. However, the first line of the text
file is not read. A single line text file never enters the while loop, and
if I copy and paste that same line into the file again, one of them (the
second one) is read and properly imported into the database.

Please help me see what I am missing. Is the ...while( kOdr.Read() )... the
proper way to prime the DataReader?

-Any help is always appreciated-

private OleDbConnection con;
private string conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=@;Extended Properties='text;FMT=Delimited(,)'";

private void OpenDb(string pDbPath)
{
string tConStr = conStr.Replace("@", pDbPath);
if( con == null )
{
con = new OleDbConnection(tConStr);
con.Open();
}
}

private void OpenTable(string pFileName, out OleDbDataReader odr)
{
string strSql = "SELECT * FROM " + pFileName;
OleDbCommand cmd = new OleDbCommand(strSql, con);
cmd.CommandType = CommandType.Text;
odr = null;
odr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
}

private void CloseDb()
{
if( con != null )
con.Close();
}

private void DisposeDb()
{
if( con != null )
{
con.Dispose();
con = null;
}
}

public void ImportData()
{
OleDbDataReader kOdr = null;
OpenDb();
OpenTable("C:\test.txt",kOdr);
while( kOdr.Read() )
{
// ...Parse Data and Import to Database...
}
kOdr = null;
CloseDb();
DisposeDb();
}


 
Reply With Quote
 
 
 
 
Carl Prothman [MVP]
Guest
Posts: n/a
 
      2nd Aug 2003
Bill,
Just a guess here... If there is no header first line in the text file,
try adding "HDR=No" to your connect string.

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
http://www.able-consulting.com


"Bill Pierce" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> I need some help/verificaion of my problem. The code below works just fine.
> Data is read from a text file using the OLE DB Jet provider, parsed, and
> then imported into another database. However, the first line of the text
> file is not read. A single line text file never enters the while loop, and
> if I copy and paste that same line into the file again, one of them (the
> second one) is read and properly imported into the database.
>
> Please help me see what I am missing. Is the ...while( kOdr.Read() )... the
> proper way to prime the DataReader?
>
> -Any help is always appreciated-
>
> private OleDbConnection con;
> private string conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=@;Extended Properties='text;FMT=Delimited(,)'";
>
> private void OpenDb(string pDbPath)
> {
> string tConStr = conStr.Replace("@", pDbPath);
> if( con == null )
> {
> con = new OleDbConnection(tConStr);
> con.Open();
> }
> }
>
> private void OpenTable(string pFileName, out OleDbDataReader odr)
> {
> string strSql = "SELECT * FROM " + pFileName;
> OleDbCommand cmd = new OleDbCommand(strSql, con);
> cmd.CommandType = CommandType.Text;
> odr = null;
> odr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
> }
>
> private void CloseDb()
> {
> if( con != null )
> con.Close();
> }
>
> private void DisposeDb()
> {
> if( con != null )
> {
> con.Dispose();
> con = null;
> }
> }
>
> public void ImportData()
> {
> OleDbDataReader kOdr = null;
> OpenDb();
> OpenTable("C:\test.txt",kOdr);
> while( kOdr.Read() )
> {
> // ...Parse Data and Import to Database...
> }
> kOdr = null;
> CloseDb();
> DisposeDb();
> }
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Free Text-To-Speech software converting text files into MP3 files comcdp Windows XP General 0 14th Feb 2008 03:30 AM
What is the easiest way to convert unix/linux text files to DIS/Win text files? Eugen Austermann Windows XP Help 9 22nd Dec 2007 02:22 AM
What is the easiest way to convert unix/linux text files to DIS/Win text files? Eugen Austermann Windows XP General 0 21st Dec 2007 04:18 PM
Re: batch comment into jpeg from a text file/group of text files Google's friend Freeware 0 8th Aug 2003 08:57 AM
Re: batch comment into jpeg from a text file/group of text files Patrick Peccatte Freeware 0 7th Aug 2003 08:28 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:33 AM.