Usuario
Leer Formato Hora Excel vb.net

Pregunta
-
Buenas. Tengo un soft. desarrollado en visual studio 2008. El tema es que mi cliente posee datos en excel y una columna tiene el dato hora con el formato 03:00:00 .... yo al leer desde el visual studio me toma con fecha y hora..... y lo que quiero es como hacer para almacenarlo como 03:00. porque lo almaceno como string.... y me almacena 30/12 o sea me esta tomando la primera parte de la fecha no de la hora... saben como resolver esto....
Gracias
Dim Excel As New DataSet
Dim DataTable As DataTable = Excel.Tables.Add("Resultado")
Dim col1 As DataColumn = DataTable.Columns.Add("Partida", Type.GetType("System.Int32"))
Dim col2 As DataColumn = DataTable.Columns.Add("Propietario", Type.GetType("System.String"))
Dim col3 As DataColumn = DataTable.Columns.Add("HectareasPermanente", Type.GetType("System.Double"))
Dim col4 As DataColumn = DataTable.Columns.Add("HectareasPREA", Type.GetType("System.Double"))
Dim col5 As DataColumn = DataTable.Columns.Add("HectareasPRED", Type.GetType("System.Double"))
Dim col6 As DataColumn = DataTable.Columns.Add("DiaInicio", Type.GetType("System.String"))
Dim col7 As DataColumn = DataTable.Columns.Add("HoraInicio", Type.GetType("System.String"))
Dim col8 As DataColumn = DataTable.Columns.Add("DiaFinal", Type.GetType("System.String"))
Dim col9 As DataColumn = DataTable.Columns.Add("HoraFinal", Type.GetType("System.String"))
Dim col10 As DataColumn = DataTable.Columns.Add("Caudal", Type.GetType("System.Double"))
Dim col11 As DataColumn = DataTable.Columns.Add("HectareasTotalCultivo1", Type.GetType("System.Double"))
Dim col12 As DataColumn = DataTable.Columns.Add("Cultivo1PS", Type.GetType("System.Double"))
Dim col13 As DataColumn = DataTable.Columns.Add("Cultivo1S", Type.GetType("System.Double"))
Dim col14 As DataColumn = DataTable.Columns.Add("HectareasTotalCultivo2", Type.GetType("System.Double"))
Dim col15 As DataColumn = DataTable.Columns.Add("Cultivo2PS", Type.GetType("System.Double"))
Dim col16 As DataColumn = DataTable.Columns.Add("Cultivo2S", Type.GetType("System.Double"))
Dim col17 As DataColumn = DataTable.Columns.Add("HectareasTotalCultivo3", Type.GetType("System.Double"))
Dim col18 As DataColumn = DataTable.Columns.Add("Cultivo3PS", Type.GetType("System.Double"))
Dim col19 As DataColumn = DataTable.Columns.Add("Cultivo3S", Type.GetType("System.Double"))
'***************************************************************
Dim conexion As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & RutaArchivo & ";Extended Properties=Excel 8.0")
Dim da As New OleDbDataAdapter("select * from [hoja1$]", conexion)
Dim ds As New DataSet
da.Fill(ds, "Resultado")
Dim i As Integer
For i = 0 To ds.Tables("Resultado").Rows.Count - 1
Dim row As DataRow = DataTable.NewRow()
If IsDBNull(ds.Tables(0).Rows(i).Item("Partida")) = False Then
row("Partida") = UCase(ds.Tables("Resultado").Rows(i).Item("Partida"))
Else
row("Partida") = 0
End If
If IsDBNull(ds.Tables(0).Rows(i).Item("Propietario")) = False Then
row("Propietario") = UCase(ds.Tables("Resultado").Rows(i).Item("Propietario"))
Else
row("Propietario") = ""
End If
If IsDBNull(ds.Tables(0).Rows(i).Item("Permanente")) = False Then
row("HectareasPermanente") = ds.Tables("Resultado").Rows(i).Item("Permanente")
Else
row("HectareasPermanente") = 0
End If
If IsDBNull(ds.Tables(0).Rows(i).Item("PREA")) = False Then
row("HectareasPREA") = ds.Tables("Resultado").Rows(i).Item("PREA")
Else
row("HectareasPREA") = 0
End If
If IsDBNull(ds.Tables(0).Rows(i).Item("PRED")) = False Then
row("HectareasPRED") = ds.Tables("Resultado").Rows(i).Item("PRED")
Else
row("HectareasPRED") = 0
End If
If IsDBNull(ds.Tables(0).Rows(i).Item("Dia Inicio")) = False Then
row("DiaInicio") = ds.Tables("Resultado").Rows(i).Item("Dia Inicio")
Else
row("DiaInicio") = ""
End If
If IsDBNull(ds.Tables(0).Rows(i).Item("Hora Inicio")) = False Then
row("HoraInicio") = ds.Tables("Resultado").Rows(i).Item("Hora Inicio")
Else
row("HoraInicio") = ""
End If
If IsDBNull(ds.Tables(0).Rows(i).Item("Dia Final")) = False Then
row("DiaFinal") = ds.Tables("Resultado").Rows(i).Item("Dia Final")
Else
row("DiaFinal") = ""
End If
If IsDBNull(ds.Tables(0).Rows(i).Item("Hora Final")) = False Then
row("HoraFinal") = ds.Tables("Resultado").Rows(i).Item("Hora Final")
Else
row("HoraFinal") = ""
End If
If IsDBNull(ds.Tables(0).Rows(i).Item("Caudal")) = False Then
row("Caudal") = ds.Tables("Resultado").Rows(i).Item("Caudal")
Else
row("Caudal") = 0
End If
If IsDBNull(ds.Tables(0).Rows(i).Item("HectareasTotalCultivo1")) = False Then
row("HectareasTotalCultivo1") = ds.Tables("Resultado").Rows(i).Item("HectareasTotalCultivo1")
Else
row("HectareasTotalCultivo1") = 0
End If
If IsDBNull(ds.Tables(0).Rows(i).Item("Cultivo1PS")) = False Then
row("Cultivo1PS") = ds.Tables("Resultado").Rows(i).Item("Cultivo1PS")
Else
row("Cultivo1PS") = 0
End If
If IsDBNull(ds.Tables(0).Rows(i).Item("Cultivo1S")) = False Then
row("Cultivo1S") = ds.Tables("Resultado").Rows(i).Item("Cultivo1S")
Else
row("Cultivo1S") = 0
End If
If IsDBNull(ds.Tables(0).Rows(i).Item("HectareasTotalCultivo2")) = False Then
row("HectareasTotalCultivo2") = ds.Tables("Resultado").Rows(i).Item("HectareasTotalCultivo2")
Else
row("HectareasTotalCultivo2") = 0
End If
If IsDBNull(ds.Tables(0).Rows(i).Item("Cultivo2PS")) = False Then
row("Cultivo2PS") = ds.Tables("Resultado").Rows(i).Item("Cultivo2PS")
Else
row("Cultivo2PS") = 0
End If
If IsDBNull(ds.Tables(0).Rows(i).Item("Cultivo2S")) = False Then
row("Cultivo2S") = ds.Tables("Resultado").Rows(i).Item("Cultivo2S")
Else
row("Cultivo2S") = 0
End If
If IsDBNull(ds.Tables(0).Rows(i).Item("HectareasTotalCultivo3")) = False Then
row("HectareasTotalCultivo3") = ds.Tables("Resultado").Rows(i).Item("HectareasTotalCultivo3")
Else
row("HectareasTotalCultivo3") = 0
End If
If IsDBNull(ds.Tables(0).Rows(i).Item("Cultivo3PS")) = False Then
row("Cultivo3PS") = ds.Tables("Resultado").Rows(i).Item("Cultivo3PS")
Else
row("Cultivo3PS") = 0
End If
If IsDBNull(ds.Tables(0).Rows(i).Item("Cultivo3S")) = False Then
row("Cultivo3S") = ds.Tables("Resultado").Rows(i).Item("Cultivo3S")
Else
row("Cultivo3S") = 0
End If
DataTable.Rows.Add(row)
Next
Dante Tagliavini
- Cambiado Enrique M. Montejo viernes, 14 de junio de 2013 7:25 Acceso a datos