ADO.Net, Jet, and Text Files

B

Bill Pierce

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();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top