如题,我ACESSS2010版本的 数据库放了60条内容,一多的话,一执行 objDataAdapter1.Update(objDate1, "设定值1") 这串代码,他就提示说System.Data.OleDb.OleDbException:“查询过于复杂。”,这个问题怎么解决?
另外我查了相关资料,说这种情况要加一段【数据源.endit()语句】,但这条语句怎么加?
附上代码如下
Public Class 设置页面
Dim objDate1 As New DataSet
Dim objDataTable1 As New DataTable
Dim objDataAdapter1 As New OleDb.OleDbDataAdapter
Dim WhereStr As String ' 保存查询条件字符串
'定义一个全局过程refreshdata用于更新物理数据库并刷新窗体中的数据显示【子程序】
Public Sub refreshdata() '更新并刷新显示
Try
objDataAdapter1.Update(objDate1, "设定值1")
objDataTable1.Clear() '清空表记录
bindgridview(WhereStr) '重新装填表格数据
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Public Sub bindgridview(ByVal strXH As String)
Dim objConnection1 As New OleDb.OleDbConnection
Dim objCommand1 As New OleDb.OleDbCommand
objConnection1.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='D:\Project\02 进行中\动静盘\程序\DongPan\DATA\DongPan.accdb'"
' 设置SQL命令,告诉程序应当如何取表格中的数
objCommand1.CommandText = "Select * From 设定值1" 'SQL语句
If Trim(strXH) <> "" Then '如果返回值strXH不是空字符,那么objCommand.CommandText和返回值与后传给自己
objCommand1.CommandText = objCommand1.CommandText & strXH
End If
' 把objConnection设置为objCommand的数据库连接,建立桥梁
objCommand1.Connection = objConnection1
objDataAdapter1.SelectCommand = objCommand1
' 创建能自动生成用于协调对 DataSet 的更改与关联物理数据库的单表命令的对象
Dim builder1 As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(objDataAdapter1)
objConnection1.Open() ' 打开数据库连接
objDataAdapter1.Fill(objDate1, "设定值1") ' 填充数据集
objDataTable1 = objDate1.Tables("设定值1")
objConnection1.Close() ' 关闭数据库连接
' 把DataGridView1的DataSource属性设置为刚刚取到的数据表,这样就可以显示数据了
DataGridView1.DataSource = objDataTable1
End Sub
Private Sub 设置页面_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If 数据显示按钮.Visible = True Then
数据显示按钮_Click(Nothing, Nothing)
End If
End Sub
Private Sub 数据显示按钮_Click(sender As Object, e As EventArgs) Handles 数据显示按钮.Click
WhereStr = ""
DataGridView1.Visible = True
If DataGridView1.Visible = True Then
数据显示按钮.Visible = False
End If
bindgridview(WhereStr) '调用bindgridview过程,读取表并且显示记录
End Sub
Private Sub 删除按钮_Click(sender As Object, e As EventArgs) Handles 删除按钮.Click
Try
Dim response As MsgBoxResult
response = MsgBox("确实要删除产品吗?", vbOKCancel + vbQuestion, "系统提示")
If response = MsgBoxResult.Ok Then ' 用户选择“确定”
objDataTable1.Rows.Item(DataGridView1.CurrentRow.Index).Delete() ' 删除设定值当前记录
objDataAdapter1.Update(objDate1, "设定值1") '更新物理数据库中的Data一栏数据
refreshdata()
数据操作成功显示.Text = "该品种已成功删除。"
类型选择IO.Text = ""
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub 添加按钮_Click(sender As Object, e As EventArgs) Handles 添加按钮.Click
Try
Dim response As MsgBoxResult
response = MsgBox("确实要添加产品吗?", vbOKCancel + vbQuestion, "系统提示")
If response = MsgBoxResult.Ok Then ' 用户选择“确定”'添加到数据库
Dim myRow As DataRow = objDataTable1.NewRow()
myRow("类型名字") = 类型选择IO.Text
objDataTable1.Rows.Add(myRow)
refreshdata()
数据操作成功显示.Text = "新品种已成功添加。"
类型选择IO.Text = ""
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub 保存按钮_Click(sender As Object, e As EventArgs) Handles 保存按钮.Click
Try
Dim response As MsgBoxResult
response = MsgBox("确实要保存设定值吗?", vbOKCancel + vbQuestion, "系统提示")
If response = MsgBoxResult.Ok Then ' 用户选择“确定”
objDataTable1.Rows.Item(DataGridView1.CurrentRow.Index).Item(1) = 类型选择IO.Text
objDataTable1.Rows.Item(DataGridView1.CurrentRow.Index).Item(2) = 验证码IO.Text
'更新并刷新纪录
objDataAdapter1.Update(objDate1, "设定值1") '更新物理数据库中的Data一栏数据
' refreshdata()
数据操作成功显示.Text = 类型选择IO.Text + "已成功保存。"
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
建议改进一下排查,支持 markdown 语法
– dudu 4年前