4/21/2021 0 Comments Read Dbf File
Some time it does require importexport data from DBF file from your DOTNET application.Currently I am working on same kind of requirement where I have developed Export Import Utility its include exportimport data from various file type.
One of toughest type is DBF file import export, I did some research on that and got one reboots solution that I want to share with you all. This document covers the following 1) How to create DBF file database table 2) How to Insert data in created DBF file 3) How to Read data from DBF file. Introduction: DBF is a FoxPro database file, this we can create from C.net application even we can use basic DDL and DML statement on this like Create table, Insert table etc. If our requirement is to export your data which in is the Dataset (in C.net) in DBF file this document will help you. Using the same function with different connection string you can use to read write excel file too. How function works. I have created one function for Export DBF file; this will takes one dataset as an input parameter 2) Based on input dataset parameter I am creating the database table using create table statement. Then I open the connection using Microsoft.Jet.OLEDB.4.0 provider. Using OleDbDataAdapter object I am filling the dataset (dsFill) this will create one DBF table structure with given table name. Now using the Same connection you can fire the next DML statement Insert into. Like table, date etc. This will take data source as folder name where DBF file exist like If you want to export Import DBF file from C:Tempcountry.dbf. Data source will be C:Temp and Table name will be country. This function takes Dataset (to be exported) and filePath as input parameter and return bool status as output parameter comments are written inside the function to describe the functionality public bool EportDBF(DataSet dsExport, string filePath) string tableName string.Empty; string folderPath string.Empty; bool returnStatus false; This function give the Folder name and table name to use in the connection string and create table statement. This function takes filePath as input parameter and return DataSet as output parameter comments are written inside the function to describe the functionality public DataSet ImportDBF( string filePath) string ImportDirPath string.Empty; string tableName string.Empty; This function give the Folder name and table name to use in the connection string and create table statement. Read Dbf File Code Was VeryThanks Ritesh Kesharwani, Your peice of code was very helpful. Just a quick note however, instead of writing GetFileNameAndPath, I suggest checking out the System.IO.Path methods which do the same thing. For example: string tableName Path.GetFileNameWithoutExtension(filePath); string folderPath Path.GetDirectoryName(filePath). Thanks Ritesh Kesharwani for such a useful article i have some pblm in generating dbf file from c.net with dbf IV oledb provider. Here is the code I am using some of the fields are hardcoded for testing. Hi Ritesh, Tried your code, inserting mutiple records in a single dbf file failed telling me Characters found after end of SQL statement., Access does not multiple insert in one sql statements, is there another way around this Thanks. Perhaps you could post this question on DoMyHomeworkForMe.com The logic is simple. Open DBF connection 2. ![]() Ive stumbled upon numerous sites that have documented that it is not possible, which supports my hours of trying every possible combination. Thanks, I modify it to take into account the data type: This for loop to create Create table statement for DBF Here I am creating varchar(250) datatype for all column. Hi Ritesh, I need to create a DBF file, but I do not have DBASE in my system.Is it possible to create a DBF file Thanks in Advance, Jaimie. Error: The field is to small to accept the amount of data you attempted to add.Try inserting or pasting less data.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |