elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Estamos en la red social de Mastodon


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Leer archivos dbf de fox en c# windows from
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Leer archivos dbf de fox en c# windows from  (Leído 5,385 veces)
hpereira

Desconectado Desconectado

Mensajes: 2


Ver Perfil
Leer archivos dbf de fox en c# windows from
« en: 28 Noviembre 2013, 17:59 pm »

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

Código
  1. private void button1_Click(object sender, EventArgs e)
  2.        {
  3.            OpenFileDialog fdlg = new OpenFileDialog();
  4.            fdlg.Title = "Seleccione un Archivo";
  5.           // fdlg.InitialDirectory = @"C:\FoxPro\CAJ&BAN\Dbf005\C&B0015.DBF\";
  6.           // fdlg.FileName = @"C:\FoxPro\NCTAXPAG\dbf002\CXP_107A.DBF";
  7.            fdlg.FileName = @"C:\FoxPro\NCTAXPAG\dbf002\CXP_FILE.DBF";
  8.            //fdlg.FileName = txtFileName.Text;
  9.            fdlg.Filter = "DBF Files(*.dbf)|CXP_ARCH.DBF";
  10.            //fdlg.Filter = "DBF Files(*.dbf)|C&B0015.DBF|All Files(*.*)|*.*";
  11.            fdlg.FilterIndex = 1;
  12.            fdlg.RestoreDirectory = true;
  13.            if (fdlg.ShowDialog() == DialogResult.OK)
  14.            {
  15.                txtFileName.Text = fdlg.FileName;
  16.                Import();
  17.                Application.DoEvents();
  18.            }
  19.        }
  20.  
  21. private void Import()
  22.        {
  23.            if (txtFileName.Text.Trim() != string.Empty)
  24.            {
  25.                try
  26.                {
  27.                    DataTable dt = GetDataTableDBF(txtFileName.Text);
  28.                    Dgvlista.DataSource = dt.DefaultView;
  29.  
  30.                }
  31.                catch (Exception ex)
  32.                {
  33.                    MessageBox.Show(ex.Message.ToString());
  34.                }
  35.            }
  36.        }
  37.  
  38. public static DataTable GetDataTableDBF(string strFileName)
  39.        {
  40.            System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection("Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" + System.IO.Path.GetFullPath(strFileName).Replace(System.IO.Path.GetFileName(strFileName), "") + ";Exclusive=No");
  41.            conn.Open();
  42.            string strQuery = "SELECT * FROM [" + System.IO.Path.GetFileName(strFileName) + "]";
  43.            System.Data.Odbc.OdbcDataAdapter adapter = new System.Data.Odbc.OdbcDataAdapter(strQuery, conn);
  44.            System.Data.DataSet ds = new System.Data.DataSet();
  45.            adapter.Fill(ds);
  46.            return ds.Tables[0];
  47.        }
  48.  
  49.  



[MOD]: Hay unas reglas que seguir, cualquier (siguiente) mensaje que no utilice las etiquetas de código podrá ser eliminado sin previo aviso.


« Última modificación: 28 Noviembre 2013, 18:38 pm por EleKtro H@cker » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Leer archivos :S
Programación Visual Basic
Thaorius 3 2,031 Último mensaje 15 Febrero 2006, 02:44 am
por Thaorius
Leer archivos
Programación Visual Basic
likeu 6 2,487 Último mensaje 25 Agosto 2006, 13:14 pm
por likeu
Leer archivos en cd/dvd - vb.net
.NET (C#, VB.NET, ASP)
rain_in!the!_universe 3 4,833 Último mensaje 22 Agosto 2007, 16:04 pm
por rain_in!the!_universe
Leer archivos // Leer un dato en concreto
Programación C/C++
uhuru 3 3,240 Último mensaje 22 Mayo 2010, 14:14 pm
por uhuru
Leer disco MBR de más de 2 TB en Windows 7 (NT 6.1)
Windows
cixert 5 5,861 Último mensaje 22 Enero 2014, 01:24 am
por cixert
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines