[英]Excel Data to Data Grid View in vb6
Hi everybody I am new! 大家好,我是新人!
So, I was developing a simple software with VB 6.0 (yeah, i know quite old). 所以,我正在用VB 6.0开发一个简单的软件(是的,我知道很老)。 I had to do is manipulate Ms Excel sheet into VB Application.
我必须做的是将Excel表格操作到VB应用程序中。 The actual task is to display the data or tables (whatever we call it)provided in the Excel sheet into Data Grid View.
实际的任务是将Excel表格中提供的数据或表格(无论我们称之为什么)显示在数据网格视图中。
I am using ADODB. 我正在使用ADODB。 Here is the code:
这是代码:
Dim file_name As String
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
file_name & ";Extended Properties=Excel 12.0;"
If cn.State = adStateOpen Then
MsgBox "Excel File is Connected. ", , "Message"
rs.CursorLocation = adUseClient
rs.Open "SELECT * FROM [Sheet1$]", cn, 3, 3, 1 - adCmdText
Set DataGrid1.DataSource = rs
DataGrid1.Refresh
DataGrid1.ReBind
Else: MsgBox "Error: Excel File is not Connected. ", , "Message"
End If
rs.Close
cn.Close
But I am facing a problem! 但我面临一个问题! Now the excel data is shown in Data Grid Control.
现在,Excel数据显示在数据网格控件中。 But immediately the data is erased after the execution of the Line "rs.close".
但是在执行“rs.close”行之后,数据立即被删除。 I am giving a snapshot.
我正在给快照。
Please Help. 请帮忙。 Thank you...
谢谢...
Here is the image: 这是图像:
你没有关闭记录集和连接...你删除rs.close和cn.close
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.