Foros del Web » Programando para Internet » ASPX (.net) »

Leer archivos dbf de fox en c# windows from

Estas en el tema de Leer archivos dbf de fox en c# windows from en el foro de ASPX (.net) en Foros del Web. Buenos días amigos tengo este problema: Como puedo leer varios archivos dbf c# y luego filtrar u buscar informacion entre ellos para luego mostralo en ...
  #1 (permalink)  
Antiguo 28/11/2013, 11:48
 
Fecha de Ingreso: abril-2010
Mensajes: 108
Antigüedad: 14 años
Puntos: 2
Leer archivos dbf de fox en c# windows from

Buenos días amigos tengo este problema:

Como puedo leer varios archivos dbf c# y luego filtrar u buscar informacion entre ellos para luego mostralo en un grid actualmente hago esto y me funciona:

Este codigo me funciona pero como ven tengo que seleccionar el archivo y me lo muestra en un grid...

Gracias
Jose Pereira


private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "Seleccione un Archivo";
// fdlg.InitialDirectory = @"C:\FoxPro\CAJ&BAN\Dbf005\C&B0015.DBF\";
// fdlg.FileName = @"C:\FoxPro\NCTAXPAG\dbf002\CXP_107A.DBF";
fdlg.FileName = @"C:\FoxPro\NCTAXPAG\dbf002\CXP_FILE.DBF";
//fdlg.FileName = txtFileName.Text;
fdlg.Filter = "DBF Files(*.dbf)|CXP_ARCH.DBF";
//fdlg.Filter = "DBF Files(*.dbf)|C&B0015.DBF|All Files(*.*)|*.*";
fdlg.FilterIndex = 1;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK)
{
txtFileName.Text = fdlg.FileName;
Import();
Application.DoEvents();
}
}

private void Import()
{
if (txtFileName.Text.Trim() != string.Empty)
{
try
{
DataTable dt = GetDataTableDBF(txtFileName.Text);
Dgvlista.DataSource = dt.DefaultView;

}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
}

public static DataTable GetDataTableDBF(string strFileName)
{
System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection("Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" + System.IO.Path.GetFullPath(strFileName).Replace(Sy stem.IO.Path.GetFileName(strFileName), "") + ";Exclusive=No");
conn.Open();
string strQuery = "SELECT * FROM [" + System.IO.Path.GetFileName(strFileName) + "]";
System.Data.Odbc.OdbcDataAdapter adapter = new System.Data.Odbc.OdbcDataAdapter(strQuery, conn);
System.Data.DataSet ds = new System.Data.DataSet();
adapter.Fill(ds);
return ds.Tables[0];
}

Etiquetas: c#
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:31.