问题描述
vbexcel导入到datagridview中出现了一些问题,谁能帮我看看吗?导入代码如下:PrivateSubbtnImport_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesbtnImport.ClickDimfileDialogAsOpenFileDialog=NewOpenFileDialog()fileDialog.InitialDirectory=My.Computer.FileSystem.CurrentDirectoryfileDialog.Filter="excelfiles(*.xls)|*.xls|Allfiles(*.*)|*.*"fileDialog.FilterIndex=2fileDialog.RestoreDirectory=TrueIffileDialog.ShowDialog()=Windows.Forms.DialogResult.OKThenDimfileNameAsStringfileName=fileDialog.FileName'建立EXCEL连接,读入数据DimstrConnAsString="Provider=Microsoft.Jet.OLEDB.4.0;DataSource='"&fileName&"';ExtendedProperties=Excel8.0;"DimmyDatasetAsNewDataSetDimdaAsNewOleDb.OleDbDataAdapter("SELECT序号asProductionID,订单编号asOrderNumber,机型代码asEngineType,机型名称asEngineName,计划数量asProduction_Plan,计划上线时间asStartTime,描述asDescriptionFROM[Sheet1$]",strConn)Tryda.Fill(myDataset)DataGridView.DataSource=myDataset.Tables(0)CatchexAsExceptionMsgBox(ex.Message.ToString)EndTryEndIfEndSubexcel表中数据如下:序号订单编号机型代码机型名称计划数量计划上线时间描述1ddd111202012-3-2813:512121fs2302012-3-2813:513aaa23www02012-3-2813:514433efwf12102012-3-299:305sss21eee02012-3-299:326344sfs2202012-3-299:327ggg222rrr02012-3-299:32导入datagridview显示结果如下:序号订单编号机型代码机型名称计划数量计划上线时间描述1ddd111202012-3-2813:5122302012-3-2813:513aaa2302012-3-2813:51412102012-3-299:305sss2102012-3-299:3262202012-3-299:327ggg22202012-3-299:32
解决方案
解决方案二:
出现的问题贴出来啊!
解决方案三:
我把代码改了一下,运行就正常了。我是vx2010。DimfileDialogAsOpenFileDialog=NewOpenFileDialog()fileDialog.InitialDirectory=My.Computer.FileSystem.CurrentDirectoryfileDialog.Filter="excelfiles(*.xls)|*.xls|Allfiles(*.*)|*.*"fileDialog.FilterIndex=2fileDialog.RestoreDirectory=TrueIffileDialog.ShowDialog()=Windows.Forms.DialogResult.OKThenDimfileNameAsStringfileName=fileDialog.FileName'建立EXCEL连接,读入数据DimstrConnAsString="Provider=Microsoft.Jet.OLEDB.4.0;DataSource='"&fileName&"';ExtendedProperties=Excel8.0;"DimmyDatasetAsNewDataSetDimdaAsNewOleDb.OleDbDataAdapter("select*FROM[Sheet1$]",strConn)DimbindinAsBindingSource=NewBindingSourceda.Fill(myDataset)bindin.DataSource=myDataset.Tables(0)DataGridView6.DataSource=bindin.DataSourceEndIf