• Jueves 18 de Abril de 2024, 07:30

Mostrar Mensajes

Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.


Mensajes - cabromex

Páginas: [1]
1
C# / PROBLEMAS CON EXCEL CONNECTION STRING
« en: Martes 3 de Diciembre de 2013, 03:21 »
SALUDOS.

TENGO UN PROBLEMA CON UN CONNECTION STRING A UNA BASE DE DATOS DE EXCEL, LO QUE PRETENDO ES QUE ESTA SE ABRA PARA QUE EL PROGRAMA LE DE LECTURA. YA LA EH TRATADO MIL VECES PERO ME SIGUE APARECIENDO UN ERROR QUE DICE: An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in ADMBD2.exe

Additional information: No se encontró "Provider=microsoft.ACE.oledb.4.0;data source=C:\Users\erik\Documents\LP_01-nov.xls;extended properties="excel 12.0;hdr=No;IMEX=1;"". Compruebe la ortografía del nombre del archivo y si su ubicación es correcta


namespace ADMBD2
{
    public partial class Form1 : Form
    {
        public string FilePath;
        public string xlsFilePath;
        public Form1()
        {
            InitializeComponent();
        }

        public void btn_buscar_Click(object sender, EventArgs e)
        {
            //BUESQUEDA DE TABAL DE EXCEL
           
            OpenFileDialog fdlg = new OpenFileDialog();
            fdlg.Title = "Busqueda de Tablas";
            fdlg.InitialDirectory = @"c:\";
            fdlg.FilterIndex = 2;
            fdlg.RestoreDirectory = true;

            if (fdlg.ShowDialog() == DialogResult.OK)
            {
                txt_buscar.Text = fdlg.FileName;
                FilePath = fdlg.FileName;
               
            }

            try
            {
           
                MessageBox.Show("Se ha seleccionado tabla de excel ! "); //ESTE ES EL PATH QUE SUPUESTAMENTE NO ES VALIDO.
                xlsFilePath = @"Provider=microsoft.ACE.oledb.4.0;data source=" + FilePath + ";extended properties=" + "\"excel 12.0;hdr=No;IMEX=1;\"";
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
           
        }


        private void Form1_Load(object sender, EventArgs e)
        {
           
        }

        private void btn_cargar_Click(object sender, EventArgs e)
        {
           
            Excel.Application xlApp;
            Excel.Workbook xlWorkbook;
            Excel.Worksheet xlWorkSheet;
            Excel.Range range;
            var misValue = Type.Missing;
           
            //abrir el documento
           
            xlApp = new Excel.Application();
            //error en el path al archivo excel
            xlWorkbook = xlApp.Workbooks.Open(xlsFilePath,misValue,misValue,misValue,misValue,misValue,misValue,misValue,misValue,misValue,misValue,misValue,misValue);

            //seleccion de la hoja de calculo
            xlWorkSheet = (Excel.Worksheet)xlWorkbook.Worksheets.get_Item(1);
            //seleccion de rango
            range = xlWorkSheet.UsedRange;

            //leer las celdas
            int rows = range.Rows.Count;
            int cols = range.Columns.Count;

            for (int row = 1; row <= rows; row++)
            {
                for (int col = 1; col <= cols; col++)
                {
                    //lectura como cadena
                    string str_value = (range.Cells[row, col] as Excel.Range).Value2.ToString();

                    //conversion
                    int int_value = Convert.ToInt32(str_value, 10);

                    Console.WriteLine("string:{0}", str_value);
                    Console.WriteLine("int:{0}", int_value);
                }
            }


        }

        private void btn_salir_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}


AQUI LES DEJO EL CODIGO

2
C# / No logro ver los botones al momento de compilar
« en: Lunes 2 de Diciembre de 2013, 04:48 »
Saludos amigos de solocodigo

Tengo una duda, eh estado haciendo un programa que migre datos de una table de excel a access, basandome en algunos ejemplos de internet. Pero ese no es el problema, el codigo no me marca ningun error, pero al momento de compilar no puedo ver ninguno de los botones que eh puesto en el Form. Como ya eh dicho no marca error pero tampoco muestra los objetos en el form cuando compila. Aqui les dejo mi codigo aunque nose si funcione debido a que no lo puedo depurar.

using System.Data.OleDb;
using System.Data.SqlClient;

namespace ExltoAccs
{
    public partial class Migrating : Form
    {
        public string excelfilepath = null;
        public void Form1()
        {
         
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            InitializeComponent();
        }

        private void btn_buscar_Click(object sender, EventArgs e)
        {
            OpenFileDialog fdlg = new OpenFileDialog();
            fdlg.Title = "Busqueda de Tablas";
            fdlg.InitialDirectory = @"c:\";
            //fdlg.Filter = "Todos los archivos (*.*)|*.*|Archivos de Excel(*.xls)|*.xls|";
            fdlg.FilterIndex = 2;
            fdlg.RestoreDirectory = true;

            if (fdlg.ShowDialog() == DialogResult.OK)
            {
                txt_buscar.Text = fdlg.FileName;
                excelfilepath = fdlg.FileName;

            }

            try
            {

                MessageBox.Show("Se ha seleccionado tabla de excel ! ");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Fallos en la conexion ! ");

            }
        }

        private void btn_cargar_Click(object sender, EventArgs e)
        {
            string accesstable = "datamigrationtable";
            string myexceldataquery = "Select datos from [LP$]";
            try
            {
                string excelconnectionstring = @"provider=microsoft.jet.oledb.4.0;data source=" + excelfilepath + ";extended properties=" + "\"excel 8.0;hdr=yes;\"";
                string accessconnectionstring = @"provider=microsoft.Ace.oledb.12.0;data source=C:\Users\erik\Documents\LP_AdmBD.mdb:JetOLEDB:Database Passwordd=null";
                //borra informacion previa de la tabla, editar para eliminar esta opcion
               string clearaccess = "delete from" + accesstable;
                OleDbConnection accsconn = new OleDbConnection(accessconnectionstring);
                OleDbCommand accscmd = new OleDbCommand(clearaccess, accsconn);
                accsconn.Open();
                //accscmd.ExecuteNonQuery();
                accsconn.Close();

                //comandos para copiar la informacion en access
                OleDbConnection oledbconn = new OleDbConnection(excelconnectionstring);
                OleDbCommand oledbcmd = new OleDbCommand(myexceldataquery, oledbconn);
                oledbconn.Open();
                OleDbDataReader dr = oledbcmd.ExecuteReader();
                SqlBulkCopy bulkcopy = new SqlBulkCopy(accessconnectionstring);
                bulkcopy.DestinationTableName = accesstable;

                while (dr.Read())
                {
                    bulkcopy.WriteToServer(dr);
                }
                accsconn.Close();
            }
            catch (Exception ex)
            {

            }
        }
    }
}

3
C# / Re:LLENAR UNA ACCESS DB DESDE UN TEXTBOX
« en: Miércoles 24 de Abril de 2013, 15:04 »
ENCONTRE LA SOLUCION, ACOMODE LOS PARAMETROS DEL COMANDO, EN EL ORDEN EN EL QUE QIERO QE VAYAN LLENADO LA TABLA Y ESO CORRIGIO EL PROBLEMA.  :nosweat:

4
C# / Re:LLENAR UNA ACCESS DB DESDE UN TEXTBOX
« en: Miércoles 24 de Abril de 2013, 14:58 »
ACABO DE OBSERVAR OTRO LIGERO INCONVENIENTE, LA INFORMACION SI SE GUARDA EN LA BASE DE DATOS, PERO NO EN LA QUE DEBERIA DE SER. NOSE SI PODRIAN DARME ALGUN CONSEJO O ALGUN MOTIVO POR EL CUAL ESTO ESTE SUCEDIENDO

5
C# / Re:LLENAR UNA ACCESS DB DESDE UN TEXTBOX
« en: Lunes 22 de Abril de 2013, 17:30 »
 :jumpie: JAJAJAJA ESE ERA TODO EL PROBLEMA???? JAJAJAJA QUE VERGUENZA, TANTAS VUELTAS QE LE DI Y NO ME DI CUENTA. MUCHAS GRACIAS

6
C# / Re:LLENAR UNA ACCESS DB DESDE UN TEXTBOX
« en: Lunes 22 de Abril de 2013, 17:18 »
LO VOY A HACER. YO AVISO SI SE SOLUCIONO EL PROBLEMA

7
C# / Re:LLENAR UNA ACCESS DB DESDE UN TEXTBOX
« en: Lunes 22 de Abril de 2013, 15:02 »
disculpen que no haya contestado ayer. la neta me eche a dormir.
ESTE ES EL CODIGO, CON ALGUNAS MODIFICACIONES. ESTA UN POCO MAS LEGIBLE
EL ERROR QUE ME MARCA ES EL SIGUIENTE:SE DETECTO OLEDBEXCEPTION No se han especificado valores para algunos de los parámetros requeridos.



 private void btn_Cotizar_Click(object sender, EventArgs e)
        {

            OleDbConnection cn = new
           OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/MEDIA/UsersPaqueteria.mdb");

            try
            {
                OleDbCommand cmd = new OleDbCommand("INSERT INTO Envios (Empresa, Contacto, Origen, Destino, Peso, NumBultos, Descripcion, Linea, CotO) VALUES  (@Empresa, @Contacto, @Origen, @Destino, @Peso, @NumBultos, @Descripcion, @Linea, @CotO)",cn);
               
               
                cmd.Parameters.AddWithValue("@Empresa",  txt_Empresa.Text);
                cmd.Parameters.AddWithValue("@Contacto", txt_Contacto.Text);
                cmd.Parameters.AddWithValue("@Destino", txt_Origen.Text);
                cmd.Parameters.AddWithValue("@Peso", txt_Peso.Text);
                cmd.Parameters.AddWithValue("@NumBultos", txt_NBultos.Text);
                cmd.Parameters.AddWithValue("@Descripcion", txt_Descripcion.Text);
                cmd.Parameters.AddWithValue("@Linea", txt_Linea.Text);
                cmd.Parameters.AddWithValue("@CotO", txt_CotO.Text);
               
                cn.Open();
                cmd.ExecuteNonQuery();
               

               
 
                MessageBox.Show("Base de Datos Actualizada");
            }

            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }

            finally
            {
                cn.Close();
            }


        }
    }
}

8
C# / LLENAR UNA ACCESS DB DESDE UN TEXTBOX
« en: Lunes 22 de Abril de 2013, 05:28 »
BUEN@S, TARDES, NOCHES DIAS.

TENGO UN LIGERO INCONVENIENTE CON UN CODIGO EN C#. LO QUE ESTOY TRATANDO DE HACER ES LLENAR UNA BASE DE DATOS DESDE LOS TEXTBOX, NO EH PUESTO UN DATA GRID PUESTO QUE NO LO VI NECESARIO.
LA BASE DE DATOS SE LLAMA USERSPAQUETERIA
LA TABLA SE LLAMA ENVIOS
LOS CAMPOS SE LLAMAN: EMPRESA, CONTACTO, ORIGEN, DESTINO, PESO, NumBultos, Descripcion, Linea Y CotO.

EN EL CATCH ME APARECE UN ERROR EL CUAL NO ENTIENDO COMO RESOLVER ADEMAS DE QUE NO HACE LO QUE SE SUPONE DEBE HACER

  private void btn_Cotizar_Click(object sender, EventArgs e)
        {
            string Empresa = txt_Empresa.Text;
            string Contacto = txt_Contacto.Text;
            string Origen = txt_Origen.Text;
            string Destino = txt_Destino.Text;
            string Peso = txt_Peso.Text;
            string NumBultos = txt_NBultos.Text;
            string Descripcion = txt_Descripcion.Text;
            string Linea = txt_Linea.Text;
            string CotO = txt_CotO.Text;

            OleDbConnection cn = new
           OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/MEDIA/UsersPaqueteria.mdb");

            try
            {
                OleDbCommand cmd = new OleDbCommand("INSERT INTO Envios ( [Empresa], [Contacto], [Origen], [Destino], [Peso], [NumBultos]s, [Descripcion], [Linea], [CotO] VALUES  (@Empresa, @Contacto, @Origen, @Destino, @Peso, @NumBultos, @Descripcion, @Linea, @CotO)",cn);
               
               // cmd.ExecuteNonQuery();//DE AQUI BRINCA EL CODIGO

                //DataSet ds = new DataSet();
               // OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                //da.Fill(ds, "Envios");

                cmd.Parameters.Add("@Empresa", OleDbType.VarChar).Value = Empresa;
                cmd.Parameters.Add("@Contacto", OleDbType.VarChar).Value = Contacto;
                cmd.Parameters.Add("@Destino", OleDbType.VarChar).Value = Destino;
                cmd.Parameters.Add("@Peso", OleDbType.VarChar).Value = Peso;
                cmd.Parameters.Add("@NumBultos", OleDbType.VarChar).Value = NumBultos;
                cmd.Parameters.Add("@Descripcion", OleDbType.VarChar).Value = Descripcion;
                cmd.Parameters.Add("@Linea", OleDbType.VarChar).Value = Linea;
                cmd.Parameters.Add("@CotO", OleDbType.VarChar).Value = CotO;
               
                cn.Open();
                cmd.ExecuteNonQuery();
               

               
 
                MessageBox.Show("Base de Datos Actualizada");
            }

            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }

            finally
            {
                cn.Close();
            }


        }
    }
}

Páginas: [1]