TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
P bimsara
NA
5
963
How to read values in a particular column of DBF file in c#
Apr 1 2019 5:04 AM
Previous, I tried Below code to read the related value from the Excel .it's work properly. now I use this code (
After changing some code
)for the read related value from the DBF files. but when I execute the above code, the output will come as a count of the columns.
please advice me.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.Word;
using System.IO;
using System.Data.OleDb;
using Microsoft.Win32;
using System.Data.Odbc;
namespace Price_check
{
public partial class File_Search : Form
{
public File_Search()
{
InitializeComponent();
}
private void btn_Attach_Click(object sender, EventArgs e)
{
string datetime = DateTime.Now.ToString("yyyyMMddHHmmss");
string LogFolder = @"C:\Log\";
try
{
string CellToRead = "A2";
string CellName = "";
Int32 CellNumber;
string fileFullPath = @"C:\Users\Pavan\Desktop\IT";
//string fileName = "CSHMIMP0.dbf";
string CellValue = "";
var alphanumericstring = new System.Text.RegularExpressions.Regex("(?[a-zA-Z]*)(?
[0-9]*)");
var match = alphanumericstring.Match(CellToRead);
CellName = match.Groups["Alpha"].Value;
int.TryParse(match.Groups["Numeric"].Value, out CellNumber);
string ConStr;
ConStr = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileFullPath + ";Extended Properties=dBASE IV; User ID=;Password=;");
OleDbConnection cnn = new OleDbConnection(ConStr);
cnn.Open();
System.Data.DataTable dtSheet = cnn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
OleDbCommand oconn = new OleDbCommand("select * from CSHMIMP0.dbf ["+CellName +(CellNumber - 1).ToString()+ ":" + CellToRead + "]", cnn);
OleDbDataAdapter adp = new OleDbDataAdapter(oconn);
System.Data.DataTable dt = new System.Data.DataTable();
adp.Fill(dt);
cnn.Close();
foreach (DataRow row in dt.Rows)
{
object[] array = row.ItemArray;
CellValue = array[0].ToString();
}
Console.WriteLine("CelltoRead :" + CellToRead + " Cell Value:" + CellValue);
Console.ReadLine();
}
catch (Exception exception)
{
using (StreamWriter sw = File.CreateText(LogFolder
+ "\\" + "ErrorLog_" + datetime + ".log"))
{
sw.WriteLine(exception.ToString());
}
}
}
}
}
Reply
Answers (
0
)
how to protect my application by hard drive serial number.
What different between Parse & TryParse in C# conversion ?