C# OLEDB DBF Querying issue with codepage invalid data - c#

Hello I'm trying to connect to a DBF and query it.
I use the following connectionstring:
string s = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(this.ShapePathFileName) + "\\;Extended Properties=dBASE IV;User ID=Admin;Password=;";
Then I want to fill a datatable it the result:
oleDbDataAdapter = new OleDbDataAdapter(selectCommand);
((DbDataAdapter)oleDbDataAdapter).Fill(dataTable);
But I've in the results values like this:
"ÒoþÚ"
but in the file I've this:
"ãoçé"
also if in the SQL statement I've WHERE name like '%é' I get no results, but with WHERE name like '%Ú' I've results
any ideas how to fix this?

Try adding
Collate=YourDbCollation
or
CodePage=YourCodePage
in the query string.
Even better than that, try donwloading an usign
VIsual FoxPro OleDB Provider
You have lot of samples of how the new query string should look like:
Visual Fox Pro Connection Strings

Related

unable to access tab delimited text file data using OleDbConnection ACE12.0

I am trying to import data from text file that is tab delimited using OleDbConnection string like below
using (OleDbConnection con =new OleDbConnection(#"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + #";Extended Properties='text;HDR=YES;FMT=TabDelimited';"))
I have provided tabDelimited option in extended properties but still i am getting data for each column upto comma ie CSV delimited.
I am importing data for the first time so this is kind of new to me.
I want to insert the data into datatable and then bulk insert the datatable into database (SQL Server) but the data is not received properly.
When using the ODBC text driver, you need to supply schema information as well.
See https://learn.microsoft.com/en-us/sql/odbc/microsoft/schema-ini-file-text-file-driver
Basically, you need to add a file named schema.ini in the same directory as your text file.
This should contain two rows:
[yourfilename.txt]
Format=TabDelimited

.Net Connection and read to a .DBF file type Visual dBase level 7 format with C#

I cannot to connect to a DBF file type Visual dBase level 7 format with C#.
I can read a DBF file type dBase III and dBase IV but with the file type DBF Visual dBase 7 Visual studio return an error message:
"the format table is not on right format expected".
Here is the follow codes I use for an console application:
static void Main(string[] args)
{
string filepath = #"C:\Users\user\Desktop\BGF\DATA\";
OdbcConnection CC =
new OdbcConnection("Driver={Microsoft dBase Driver
(*.dbf)};SourceType=DBF;SourceDB=" + filepath + ";Exclusive=No;
Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;");
CC.Open();
OdbcCommand cmd = new OdbcCommand("Select * From MyDBF_file", CC);
OdbcDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
DataTable dt = new DataTable();
dt.Load(dr);
}
CC.Close();
`enter code here`Console.WriteLine("Successful");
Console.Read();
}
I think the provider is not compatible, but I have tried with Microsoft.Jet.OLEDB.4.0 does not work.
And with vfpoledb provider same problem.
I have tried with simple query as
OdbcCommand cmd = new OdbcCommand("Select * From MyDBF_file", CC);
And same problem :-(
Thx in advance for your help or for all approach contribute to a part of solution ;-)
You appear to be correct on the CONNECTION. That should be to the PATH where the tables are located. However, you QUERY should
select * from SomeTableWithinThatPath
You are trying to query the PATH, not a specific table.
For Visual dBase level 7 format this connections will not work.
You can use code library of dBase IV reader and modify headers to work with Dbase 7 files.
You can find Dbase 7 header information from here.
http://www.dbase.com/KnowledgeBase/int/db7_file_fmt.htm
And DBF reader for older version from here.
https://github.com/eXavera/NDbfReader

sqlite c# generated open on as3

I have a DB that is generated by C# code, and when i'm creating it I use the connection string I use
new SQLiteConnection("Data Source=" + dbPath + ";Version=3;New=False;Compress=True;Password=1234");
The database is created with success but when I download it to my computer and try to read in on adobe air I can't seem to open the database. The only way of passing password to the connection is passing it by bytearray but I can't get it right.
My as3 code is like this:
_connection = new SQLConnection();
_connection.addEventListener(SQLEvent.OPEN, onDatabaseOpen);
_connection.addEventListener(SQLEvent.CLOSE, onDatabaseClose);
_connection.addEventListener(SQLErrorEvent.ERROR, onDatabaseError);
var ba:ByteArray = new ByteArray();
ba.writeMultiByte("1234","unicode");
_connection.open(_mydatabaseFile,SQLMode.READ,false,1024,ba);
It always gets an error because of the length of the bytearray.
Edit:
I forgot to mention, if i don't put the password on the conection i can open the database without problem using just _connection.open(_mydatabaseFile)
Thanks in advance
Alex

Import Excel to database in C#.NET

I have a huge collection of Excel files. there are many information privite and my client want to store it in database. And later they can use the data in the database to rebuild all the Excel report. So do you have any idea to achieve that? what if I convert Excel to byte stream to store?
I know that if i put Excel to byte stream, will use more time and space to handle like formats and other thing, and stupid to do that. So I would like other way to store the data?
As Uriel_SVK said, Interop.Excel should be easy to achieve that. But if you just wish to store datas, can also have a try with Oledb.
string myConnection ="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\test.xlsx;Extended Properties="Excel 12.0 ;HDR=YES";
OleDbConnection conn = new OleDbConnection(connstr);
string strSQL = "SELECT * FROM [Sheet$]";
OleDbCommand cmd = new OleDbCommand(strSQL, conn);
DataSet dataset = new DataSet();
OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
adapter.Fill(dataset);
GridViewXYZ.DataSource = dataset;
GridViewXYZ.DataBind();
Are you constrained to using C#? Certain versions of SQL Server offer DTS or SSIS services for moving data in and out of the database from various sources/destinations such as Excel files. Oracle has something similar in OWB.
You can use Jet OleDB.
The sheet will be the tables and the workbook will be the database. You can use SQl query to produce the data what you want and save it on a datatable/dataset

Reading Excel files with OleDb or ExcelDataReader return special characters encoded wronlgy

I need to read an EXCEL binary file (xls) in C#.
Basically its working, but i have problems with wrongly encoded characters (german umlauts for example).
Is there some way to specify an encoding? Does Excel files have something like an encoding at all?
The string in the Excel File is
Lydia Hömmerl
When reading with Jet or EDR i get:
Lydia HŠmmerl
I have tried OleDb and the Excel Data Reader project.
Here is the code i use to open and read the file:
var connectionString =
string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0};
Extended Properties=\"Excel 8.0;HDR=no\";", filePath);
var adapter = new OleDbDataAdapter(
"SELECT * FROM [Webshop orders$]", connectionString);
var ds = new DataSet();
adapter.Fill(ds, "Orders");
var data = ds.Tables["Orders"].AsEnumerable();
foreach (var row in data)
{
var str = Convert.ToString(row[0]);
Unicode with C#
There are still many people who don't understand the difference between binary and text, or know what a character encoding is, etc. It is for these people that this page has been written. It mentions a few advanced topics, but only to make the reader aware of their existence, rather than to give much guidance on the topic.

Categories

Resources