Acessando Tabela DBF
/*
Autor: suhas hegde
Fonte: http://www.foxite.com/archives/c-and-dbf-0000222619.htm
*/
using System;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
using System.Drawing;
class vfpData
{
static void Main()
{
string strConn = @"Provider=VFPOLEDB;Data source=
C:\Program Files\Microsoft Visual FoxPro 9\Samples\Data;";
OleDbConnection cn = new OleDbConnection(strConn);
cn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.Connection = cn;
cmd.CommandText = "delete from customer";
cmd.ExecuteNonQuery();
OleDbCommand cmd1 = new OleDbCommand();
cmd1.Connection = cn;
cmd1.CommandText = "Set Deleted off";
cmd1.ExecuteNonQuery();
cmd1.CommandType = CommandType.Text;
cmd1.CommandText = "select deleted() as isdeleted ,* from customer";
OleDbCommand cmd2 = new OleDbCommand();
cmd2.CommandType = CommandType.TableDirect;
cmd2.Connection = cn;
cmd2.CommandText = "customer";
DataTable tbl1 = new DataTable();
DataTable tbl2 = new DataTable();
OleDbDataReader rdr1 = cmd1.ExecuteReader();
tbl1.Load(rdr1);
OleDbDataReader rdr2 = cmd2.ExecuteReader();
tbl2.Load(rdr2);
cn.Close();
Form f = new ShowDataForm(tbl1, "Select command");
f.ShowDialog();
f = new ShowDataForm(tbl2, "Table direct");
f.ShowDialog();
}
}
public class ShowDataForm : Form
{
public ShowDataForm(DataTable tbl, string caption)
{
this.dgv = new System.Windows.Forms.DataGridView();
this.dgv.Location = new System.Drawing.Point(0, 0);
this.dgv.Dock = DockStyle.Fill;
this.dgv.DataSource = tbl;
this.Text = caption + " Records fetched " + tbl.Rows.Count.ToString();
this.Controls.Add(this.dgv);
this.ClientSize = new System.Drawing.Size(1024, 768);
}
private System.Windows.Forms.DataGridView dgv;
}
Sem comentários:
Enviar um comentário