本文介绍了将NewRow添加到.mdb问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
使用oledb连接将表加载到mdb文件时,出现内存不足异常.该表有超过60万条记录,文件大小不会超过150 mb.我们的服务器中有该空间.仍然给我们例外.
有人可以告诉我解决方案吗?请在下面找到代码.
Hi Guys,
I''m getting an Outofmemory Exception while loading a table into an mdb file using oledb connection. the table is having more than 6 lakh records and the file size will not 150 mb. we have that space in our server. still it is giving us exception.
Can any one tell me the solution for this? Please find the code below.
Dim SqlDs As New DataSet
Dim Conn As New SqlConnection(SQLNativeConnStr)
Conn.Open()
Dim SQLStr As String = "SELECT * FROM " & TableName & ""
Dim SqlAdp As SqlDataAdapter = New SqlDataAdapter(SQLStr, Conn)
SqlAdp.Fill(SqlDs)
Conn.Close()
Dim dt As DataTable = SqlDs.Tables(0)
'Dim OleDbCon As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileLoadPath & ";")
'OleDbCon.Open()
'Dim OleDbCmd As OleDbCommand = New OleDbCommand(MdbTableScript, OleDbCon)
'OleDbCmd.ExecuteNonQuery()
'OleDbCon.Close()
Dim SqlQuery As String = "SELECT * FROM [" & TableName & "]"
Dim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileLoadPath & ";"
Dim Adapter As New OleDbDataAdapter(SqlQuery, ConnString)
Dim CmdBuilder As New OleDbCommandBuilder(Adapter)
CmdBuilder.QuotePrefix = "["
CmdBuilder.QuoteSuffix = "]"
Dim ds As New DataSet
Adapter.FillSchema(ds, SchemaType.Source)
ds.Tables(0).TableName = "Temp"
For i As Integer = 0 To dt.Rows.Count - 1
Dim RowValues(ds.Tables(0).Columns.Count - 1) As Object
For j As Integer = 0 To ds.Tables(0).Columns.Count - 1
If dt.Rows(i)(j).ToString().ToUpper() = "" Then
If ds.Tables(0).Columns(j).DataType.ToString() = "System.String" Then
RowValues(j) = ""
Else
RowValues(j) = 0
End If
Else
RowValues(j) = dt.Rows(i)(j).ToString()
End If
Next
ds.Tables(0).Rows.Add(RowValues)
Next
Adapter.Update(ds, "Temp")
Adapter.Dispose()
在此先感谢
问候,
Srinivas.
Thanks in advance
Regards,
Srinivas.
推荐答案
这篇关于将NewRow添加到.mdb问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!