如何与excel保持连接,快速获取数据

我正在做一个交易网站,交易饲料来源于Excel表格。 我必须在gridview中显示Excel表格中的数据。 当我build立连接时,由于数据快速变化,它会失败; 表单中的每个单元格每秒更改一次值1-3次。 我正在使用间隔100的Ajax计时器。这是我的代码:

Public Function RetrieveExcelData(ByVal excelSheetName As String, ByVal sheetNumber As Integer) As DataSet Dim objConn As OleDbConnection = Nothing Dim dt As System.Data.DataTable = Nothing Try ' Connection String. Dim connString As [String] = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\Users\Vishal\Desktop\TESTING COLOURfor web1.xls;Extended Properties=Excel 8.0;" ' Create connection object by using the preceding connection string. objConn = New OleDbConnection(connString) ' Open connection with the database. objConn.Open() ' Get the data table containg the schema guid. dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing) If dt Is Nothing Then Return Nothing End If Dim excelSheets As [String]() = New [String](dt.Rows.Count - 1) {} Dim i As Integer = 0 ' Add the sheet name to the string array. For Each row As DataRow In dt.Rows excelSheets(i) = row("TABLE_NAME").ToString() i += 1 If i = sheetNumber Then Exit For End If Next Dim excelCommand As New OleDbCommand("Select * from [" + excelSheets(sheetNumber - 1) & "]", objConn) Dim excelAdapter As New OleDbDataAdapter(excelCommand) Dim excelDataSet As New DataSet() excelAdapter.Fill(excelDataSet) Return excelDataSet Catch ex As OleDbException Throw ex Catch ex As Exception Throw ex Finally ' Clean up. If objConn IsNot Nothing Then objConn.Close() objConn.Dispose() End If If dt IsNot Nothing Then dt.Dispose() End If End Try End Function 

说实话 – 我看不出它是如何工作的。 您正在尝试使用Excel电子表格作为数据库来实时存储和检索数据,而Excel从未打算或devise过该数据。

你已经提到,Excel每秒获取数据数次。 数据的来源是什么? RTD组件? 彭博API? 我会尽量避免在电子表格中存储数据的中间步骤。