473,406 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

View a DBF file in DataGridView using C#

Hi all,

I am trying to use datagridview to view a dbf file. It is a single dbf file and is not a part of any database. How do I do this in Visual Studio 2005 using C#.

Could you help me my providing me with a code to use for this purpose?

Your help in this matter is highly appreciated.

Thanking you in advance.

Regards,
Deepak
Aug 7 '07 #1
2 11379
Expand|Select|Wrap|Line Numbers
  1. using System.Data.OleDb; 
  2.         private void ImportDBF_Load(object sender, EventArgs e) 
  3.         { 
  4.             if (ofdDBF.ShowDialog()==DialogResult.OK) 
  5.             { 
  6.                 string connStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ofdDBF.FileName.Substring(0, ofdDBF.FileName.LastIndexOf("\\")) + ";Extended Properties=dBASE IV;"; 
  7.  
  8.                 OleDbConnection conn = new OleDbConnection(connStr); 
  9.                 conn.Open(); 
  10.  
  11.                 string cmd_string = "select * from " + ofdDBF.SafeFileName.Substring(0, ofdDBF.SafeFileName.IndexOf(".")); 
  12.                 MessageBox.Show(cmd_string); 
  13.                 OleDbDataAdapter da = new OleDbDataAdapter(cmd_string, conn); 
  14.                 DataSet ds = new DataSet(); 
  15.                 da.Fill(ds); 
  16.                 dgvImport.DataSource = ds.Tables[0]; 
  17.  
  18.             } 
  19.  
  20.         }

I hope it's useful .
Feb 5 '09 #2
Frinavale
9,735 Expert Mod 8TB
The code above retrieves the data from the DBF file and loads it into memory...then it uses this as the data source for the DataGridView's.

For more information on how to use a database in your programs please see how to use a database in your program. Also, take a look at how to use a database in your program part II for more information on how to connect to databases that are not MSSql.
Feb 5 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: MadCrazyNewbie | last post by:
Hi Group, I have the following code, but not sure if this is write, I would like to be able with the View code, for the document to be opened eg. C:\test.Doc and with the PRint button for it to...
9
by: Prakash_Joy | last post by:
I am trying to surf the web application (developed in ASP.NET)which is there in my personal system .I am getting the error while accessing the link : Cannot view XML input using XSL style sheet....
3
by: Lars E. Nes | last post by:
Hi all. I would like to automaticly select a item in a datagridview using the value of column. I do not have the index. Just the value (which is a string). How can this be done? Thanks.
0
by: jonny | last post by:
The XML page cannot be displayed Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later. ...
0
by: betchay1219 | last post by:
Can you give me sample codes to databind a datagridview using vb.net
2
by: sreenu123 | last post by:
Hi How to clear records in DataGridView using C# Regards Sreeni
2
by: tanuja5 | last post by:
hi.. how to delete the selected row in datagridview using ContextMenuStrip.When i right-click and press "delete" the seleted row in the dataGridView has to be deleted and as well in my access...
7
by: moro145 | last post by:
Hi I deleted my massenger history files xml and i could recover them full size but when i open then i get this error massage : The XML page cannot be displayed Cannot view XML input using...
1
by: moro145 | last post by:
Hi I deleted my massenger history files xml and i could recover them full size but when i open then i get this error massage : The XML page cannot be displayed Cannot view XML input using...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.