DateTime format mismatch on importing from Excel Sheet

后端 未结 10 2188
旧巷少年郎
旧巷少年郎 2020-12-17 21:36

I\'m importing data from an Excel sheet on to a DataTable using the following code:

OleDbConnection con = new OleDbConnection(\"Provider=Microso         


        
10条回答
  •  忘掉有多难
    2020-12-17 22:05

    How about filling the dataset programmatically instead of via a data adapter?

    OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties=Excel 8.0");
    
    Dim _myDataSet As New DataSet
                    Dim con As New OleDb.OleDbConnection
                    con.Open()
                    Dim cmd As New OleDb.OleDbCommand(" SELECT * FROM [" + "Sheet1" + "$]", con)
                    Using dr = cmd.ExecuteReader()
                        While dr.Read
                            Dim row = _myDataSet.Tables(0).NewRow()
                            With dr.Item("excel date column").ToString
                                Dim dt As New Date(CInt(.Substring(6)), CInt(.Substring(3, 2)), CInt(.Substring(0, 2)))
                                row.Item("dataset datecolumn") = dt
                            End With
    
                            \*'populate other columns here' *\
                           _myDataSet.Tables(0).Rows.Add(row)
                        End While
    
    
                    End Using
    

提交回复
热议问题