dkloeck
asked on
read DBF file
hi there,
I need to read information from a .dbf file which is part of a shapefile (http://es.wikipedia.org/wiki/Shapefile)
to populate an information window.
Anyone knows how to do it?
I need to read information from a .dbf file which is part of a shapefile (http://es.wikipedia.org/wiki/Shapefile)
to populate an information window.
Anyone knows how to do it?
ASKER
i have to do it programatically, so i can not open anything with other programs.
Isn't there a way to read the colums just using c# methods?
or just parsting the file?
btw. thanks for the fast answer ^_^
Isn't there a way to read the colums just using c# methods?
or just parsting the file?
btw. thanks for the fast answer ^_^
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I used following code:
try
{
string connectionString = "Driver={Microsoft dBASE Driver (*.dbf)};DBQ=C:\\gm.dbf";
OdbcConnection conn = new OdbcConnection(connectionS tring);
OdbcCommand command = new OdbcCommand("SELECT * FROM tablename",conn);
DataSet ds = new DataSet();
OdbcDataAdapter da = new OdbcDataAdapter(command);
da.Fill(ds);
foreach(DataColumn ncolumn in ds.Tables[0].Columns)
{
textBox1.Text+=ncolumn.Col umnName.To String()+" : "+ncolumn.DataType.ToStrin g();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToStrin g());
}
and i get following error:
"System.Data.Odbc.OdbcExce ption: ERROR [HY024] [Microsoft][ODBC dBASE Driver] '(unbekannt)' ist kein zulässiger Pfad. Stellen Sie sicher, dass der Pfad richtig eingegeben wurde und dass Sie mit dem Server, auf dem sich die Datei befindet, verbunden sind.
ERROR [IM006] [Microsoft][ODBC Driver Manager] Fehler bei SQLSetConnectAttr-Aufruf für Treiber
ERROR [HY024] [Microsoft][ODBC dBASE Driver] '(unbekannt)' ist kein zulässiger Pfad. Stellen Sie sicher, dass der Pfad richtig eingegeben wurde und dass Sie mit dem Server, auf dem sich die Datei befindet, verbunden sind.
at System.Data.Odbc.OdbcConne ction.Open ()
at System.Data.Common.DbDataA dapter.Qui etOpen(IDb Connection connection, ConnectionState& originalState)
at System.Data.Common.DbDataA dapter.Fil lFromComma nd(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataA dapter.Fil l(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataA dapter.Fil l(DataSet dataSet)
at DBFReader.Form1.button1_Cl ick(Object sender, EventArgs e) in f:\software dani\visual studio projects\tests\ziptest\dbf reader\for m1.cs:line 111"
try
{
string connectionString = "Driver={Microsoft dBASE Driver (*.dbf)};DBQ=C:\\gm.dbf";
OdbcConnection conn = new OdbcConnection(connectionS
OdbcCommand command = new OdbcCommand("SELECT * FROM tablename",conn);
DataSet ds = new DataSet();
OdbcDataAdapter da = new OdbcDataAdapter(command);
da.Fill(ds);
foreach(DataColumn ncolumn in ds.Tables[0].Columns)
{
textBox1.Text+=ncolumn.Col
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToStrin
}
and i get following error:
"System.Data.Odbc.OdbcExce
ERROR [IM006] [Microsoft][ODBC Driver Manager] Fehler bei SQLSetConnectAttr-Aufruf für Treiber
ERROR [HY024] [Microsoft][ODBC dBASE Driver] '(unbekannt)' ist kein zulässiger Pfad. Stellen Sie sicher, dass der Pfad richtig eingegeben wurde und dass Sie mit dem Server, auf dem sich die Datei befindet, verbunden sind.
at System.Data.Odbc.OdbcConne
at System.Data.Common.DbDataA
at System.Data.Common.DbDataA
at System.Data.Common.DbDataA
at System.Data.Common.DbDataA
at DBFReader.Form1.button1_Cl
ASKER
it seems that the path is wrong.. ("DBQ=C:\\gm.dbf")
is it not right to put the path to the file I want to open there?
is it not right to put the path to the file I want to open there?
Put the directory in the connection string, not the file name. The file name will be specified in the SELECT query.
string connectionString = "Driver={Microsoft dBASE Driver (*.dbf)};DBQ=C:\\";
OdbcConnection conn = new OdbcConnection(connectionS tring);
OdbcCommand command = new OdbcCommand("SELECT * FROM gm",conn);
string connectionString = "Driver={Microsoft dBASE Driver (*.dbf)};DBQ=C:\\";
OdbcConnection conn = new OdbcConnection(connectionS
OdbcCommand command = new OdbcCommand("SELECT * FROM gm",conn);
OdbcConnection conn = new OdbcConnection(@"Driver={M
OdbcCommand command = new OdbcCommand("SELECT * FROM tablename",conn);