Cargar excel devuelve celdas de fecha valor nulo

Hola expertos
utilizo el siguiente código para cargar un archivo excel
Dim cn As System.Data.OleDb.OleDbConnection
Dim cmd As System.Data.OleDb.OleDbDataAdapter
'asumir una conexión válida para cn
cmd = New System.Data.OleDb.OleDbDataAdapter("select * from [productos$A7:AZ]", cn)
cn.Open()
cmd.Fill(ds)
este código me carga la tabla con la dificultad que una columna de tipo fecha toma valores nulos.
Cuál puede ser el problema o si conoce una forma alternativa que funcione que me sugiera.
Gracias de antemano.
cn.Close()

1 Respuesta

Respuesta
1
Te recomiendo cambiar el atributo del excel a string y probar. Cuando el query te traiga la fecha como un strin lo puedes cambiar a date en el codigo VB. De todas maneras revisa este codigo de MSDN. MSDN recomienda el Jet 4.0.
/////
// Create connection string variable. Modify the "Data Source" // parameter as appropriate for your environment. String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("../ExcelData.xls") + ";" + "Extended Properties=Excel 8.0;"; // Create connection object by using the preceding connection string. OleDbConnection objConn = new OleDbConnection(sConnectionString); // Open connection with the database. objConn.Open(); // The code to follow uses a SQL SELECT command to display the data from the worksheet. // Create new OleDbCommand to return data from worksheet. OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM myRange1", objConn); // Create new OleDbDataAdapter that is used to build a DataSet // based on the preceding SQL SELECT statement. OleDbDataAdapter objAdapter1 = new OleDbDataAdapter(); // Pass the Select command to the adapter. objAdapter1.SelectCommand = objCmdSelect; // Create new DataSet to hold information from the worksheet. DataSet objDataset1 = new DataSet(); // Fill the DataSet with the information from the worksheet. objAdapter1.Fill(objDataset1, "XLData"); // Bind data to DataGrid control. DataGrid1.DataSource = objDataset1.Tables[0].DefaultView; DataGrid1.DataBind(); // Clean up objects. objConn.Close();

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas