Article View: alt.pl.comp.lang.csharp
Article #21573Re: c# i dbf
From: Tadeusz Olszewski
Date: Sat, 12 Jun 2010 09:34
Date: Sat, 12 Jun 2010 09:34
79 lines
3682 bytes
3682 bytes
Użytkownik "TheBest" <colbyco@gazeta.pl> napisał w wiadomości
news:t2pbe7-88m.ln1@alfa.polanka.net.pl...
> qaz pisze:
>> Jak przeczytać tabele Visual Fox Pro (.dbf ) ?
>
> OLE DB
> http://www.microsoft.com/downloads/details.ASPx?familyid=e1a87d8f-2d58-491f-a0fa-95a3289c5fd4&displaylang=en
> jest z tymi tabelami tylko jeden problem - wydajnosc
1. A jakie ilości danych chcesz przetwarzać?
2. Czy pliki .dbf, które przetwarzasz to rzeczywiście pliki pochodzące od
Foxa czy może dBase czy dBase4 a może jeszcze coś innego?
Po kilku próbach, rozwiązania problemu pod tytułem czytanie plików dba i
zapis do plików ja wybrałem takie rozwiązanie:
Czytanie:
public DataTable GetData(string file)
{
System.Data.OleDb.OleDbConnection conn = new
System.Data.OleDb.OleDbConnection();
string directory = System.IO.Path.GetDirectoryName(file);
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" + directory + ";Extended Properties=dBASE IV;User
ID=Admin;Password=";
conn.Open();
System.Data.OleDb.OleDbCommand cmd = conn.CreateCommand();
cmd.CommandText = @"SELECT * FROM " + file;
DataTable dt = new DataTable();
dt.Load(cmd.ExecuteReader());
conn.Close();
return dt;
}
Zapis:
internal void SaveData(string dbfFile, DataTable dt)
{
string directory = System.IO.Path.GetDirectoryName(file);
if (directory.Substring(directory.Length - 1, 1) != @"\")
directory += @"\";
OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" + directory + ";Extended Properties=dBASE IV;User
ID=Admin;Password=";
conn.Open();
System.Data.OleDb.OleDbCommand cmdSelect = conn.CreateCommand();
cmdSelect.CommandType = CommandType.Text;
cmdSelect.CommandText = @"SELECT * FROM " + file;
DataTable dtSelect = new DataTable();
dtSelect.Load(cmdSelect.ExecuteReader());
OleDbDataAdapter dbfAdapter = new
OleDbDataAdapter(cmdSelect.CommandText, conn);
dbfAdapter.Fill(dbfDt);
OleDbCommandBuilder builder = new
OleDbCommandBuilder(dbfAdapter);
System.Data.OleDb.OleDbCommand insertCmd =
builder.GetInsertCommand();
dbfAdapter.InsertCommand = insertCmd;
dbfAdapter.Update(dt);
dbfAdapter.Dispose();
conn.Close();
}
Technical Details
Message-ID:
<huvkh0$2qv6$1@news.mm.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!nf1.ipartners.pl!ipartners.pl!news.task.gda.pl!news.mm.pl!not-for-mailReferences:
<4c11e5b8$0$17095$65785112@news.neostrada.pl> <t2pbe7-88m.ln1@alfa.polanka.net.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!nf1.ipartners.pl!ipartners.pl!news.task.gda.pl!news.mm.pl!not-for-mail From: "Tadeusz Olszewski" <olszewski.tadeusz.usun@wp.pl> Newsgroups: alt.pl.comp.lang.csharp Subject: Re: c# i dbf Date: Sat, 12 Jun 2010 11:34:51 +0200 Organization: Multimedia Polska SA Lines: 82 Message-ID: <huvkh0$2qv6$1@news.mm.pl> References: <4c11e5b8$0$17095$65785112@news.neostrada.pl> <t2pbe7-88m.ln1@alfa.polanka.net.pl> NNTP-Posting-Host: host-89-228-39-17.elk.mm.pl Mime-Version: 1.0 X-Trace: news.mm.pl 1276335456 93158 89.228.39.17 (12 Jun 2010 09:37:36 GMT) X-Complaints-To: abuse@multimedia.pl NNTP-Posting-Date: Sat, 12 Jun 2010 09:37:36 +0000 (UTC) In-Reply-To: <t2pbe7-88m.ln1@alfa.polanka.net.pl> X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Windows Mail 6.0.6002.18197 X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6002.18197 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit