473,473 Members | 1,825 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

View a DBF file in DataGridView using C#

2 New Member
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 11385
it577net
1 New Member
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 Recognized Expert Moderator Expert
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
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
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
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.