RESPONDER UNA PREGUNTA

Si para responder la pregunta, crees necesario enviar un archivo adjunto, puedes hacerlo a traves del correo [email protected]

    Pregunta:  66286 - OLEDB Y EXCEL
Autor:  Jonathan
Hola que tal, espero me puedan ayudar con mi problema la verdad es que ya llevo varios dias tratando de solucionarlo y no lo logro.
Tengo un proyecto de C# en visual studio 2010 con el cual agrego un dato a una celda de excel, al hacer esto se carga otro form en donde esta un datagrid que desplegara una lista afectada por el dato anterior. El problema es que no se actualizan los datos en el gridview, cuando abro el archivo de excel lo estan pero en mi programa no. Como puedo solucionar esto??

Agrego mi codigo

Para el form1

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.Data.OleDb;

namespace Programa_7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string cad_cnx = (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:UsersLaptopDocuments6 SemestreControl NumericoPosibles programasBase_Programa_7.xlsx;Extended Properties=""Excel 8.0;HDR=NO;IMEX=0;""");
OleDbConnection Cnx = new OleDbConnection(cad_cnx);

try
{
Cnx.Open();
}

catch
{
MessageBox.Show("Imposible conectar");
}

OleDbCommand Cmd = new OleDbCommand();
Cmd.Connection = Cnx;
OleDbTransaction Trans = Cnx.BeginTransaction();
Cmd.Transaction = Trans;

try
{
string consulta = "UPDATE [Hoja2$] SET Dato = @valor";
OleDbParameter ptr = new OleDbParameter("@valor", textBox1.Text);
Cmd.CommandText = consulta;
Cmd.Parameters.Add(ptr);
Cmd.ExecuteNonQuery();

Trans.Commit();
}

catch
{
Trans.Rollback();
}

finally
{
Cnx.Close();
}

Form2 frm2 = new Form2();
frm2.Show();
}
}
}

Y este es el form 2 que me esta causando problemas

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.Data.OleDb;

namespace Programa_7
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void Form2_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
string cad_cnx = (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:UsersLaptopDocuments6 SemestreControl NumericoPosibles programasBase_Programa_7.xlsx;Extended Properties=""Excel 8.0;HDR=NO;IMEX=0;""");
OleDbConnection Cnx = new OleDbConnection(cad_cnx);

try
{
Cnx.Open();
}

catch
{
MessageBox.Show("Imposible conectar");
}

OleDbDataAdapter DtA = new OleDbDataAdapter();
OleDbCommand Cmd = new OleDbCommand();
Cmd.Connection = Cnx;
DataSet DtSet = new DataSet();

try
{
string consulta = "select * from [Hoja1$]";
DtA = new OleDbDataAdapter(consulta, cad_cnx);
DtA.Fill(DtSet);
dataGridView1.DataSource = DtSet.Tables[0];
}

finally
{
Cnx.Close();
}
}

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

Espero su respuesta y muchas gracias por el tiempo que se toman en leer esto.


Nombre
Apellidos
Correo
Comentarios