怎样将Datagrid控件重新绑定到ADODC1控件,并设定表格的状态 35
PrivateSubCommand1_Click()DimsqlAsStringIfCheck1.Value=vbCheckedThensql="书名='"&Trim(T...
Private Sub Command1_Click()
Dim sql As String
If Check1.Value = vbChecked Then
sql = "书名='" & Trim(Text1.Text & "") & "'"
End If
If Check2.Value = vbChecked Then
If Trim(sql) = "" Then
sql = "图书类别='" & Trim(Combo1.Text & "") & "'"
Else
sql = sql & "and 图书类别='" & Trim(Combo1.Text & "") & "'"
End If
End If
If Check3.Value = vbChecked Then
If Trim(sql) = "" Then
sql = "作者='" & Trim(Text2.Text & "") & "'"
Else
sql = sql & "and 作者='" & Trim(Text2.Text & "") & "'"
End If
End If
If Check4.Value = vbChecked Then
If Trim(sql) = "" Then
sql = "出版社='" & Trim(Text3.Text & "") & "'"
Else
sql = sql & "and 出版社='" & Trim(Text3.Text & "") & "'"
End If
End If
If Check5.Value = vbChecked Then
If Trim(sql) = "" Then
sql = "编号='" & Trim(Text4.Text & "") & "'"
Else
sql = sql & "and 编号='" & Trim(Text4.Text & "") & "'"
End If
End If
If Trim(sql) = "" Then
MsgBox "请选择查询方式!", vbOKOnly + vbExclamation
Exit Sub
End If
Adodc1.RecordSource = "select * from 书籍信息 where" & sql
Set DataGrid1.DataSource = Adodc1.Recordset
Adodc1.Refresh(提示错误说from子句语法错误)
DataGrid1.ReBind
DataGrid1.AllowAddNew = False
DataGrid1.AllowDelete = False
DataGrid1.AllowUpdate = False
End Sub
书本上说是要在绑定数据源之后,键入查询条件,刷新adodc1,同时将Datagrid控件重新绑定到adodc1上,并设定表格的状态,要怎么做呢?我刚学vb,谢谢大家了,改了一天程序了,怎么都出不来,各位帮帮忙啊~! 展开
Dim sql As String
If Check1.Value = vbChecked Then
sql = "书名='" & Trim(Text1.Text & "") & "'"
End If
If Check2.Value = vbChecked Then
If Trim(sql) = "" Then
sql = "图书类别='" & Trim(Combo1.Text & "") & "'"
Else
sql = sql & "and 图书类别='" & Trim(Combo1.Text & "") & "'"
End If
End If
If Check3.Value = vbChecked Then
If Trim(sql) = "" Then
sql = "作者='" & Trim(Text2.Text & "") & "'"
Else
sql = sql & "and 作者='" & Trim(Text2.Text & "") & "'"
End If
End If
If Check4.Value = vbChecked Then
If Trim(sql) = "" Then
sql = "出版社='" & Trim(Text3.Text & "") & "'"
Else
sql = sql & "and 出版社='" & Trim(Text3.Text & "") & "'"
End If
End If
If Check5.Value = vbChecked Then
If Trim(sql) = "" Then
sql = "编号='" & Trim(Text4.Text & "") & "'"
Else
sql = sql & "and 编号='" & Trim(Text4.Text & "") & "'"
End If
End If
If Trim(sql) = "" Then
MsgBox "请选择查询方式!", vbOKOnly + vbExclamation
Exit Sub
End If
Adodc1.RecordSource = "select * from 书籍信息 where" & sql
Set DataGrid1.DataSource = Adodc1.Recordset
Adodc1.Refresh(提示错误说from子句语法错误)
DataGrid1.ReBind
DataGrid1.AllowAddNew = False
DataGrid1.AllowDelete = False
DataGrid1.AllowUpdate = False
End Sub
书本上说是要在绑定数据源之后,键入查询条件,刷新adodc1,同时将Datagrid控件重新绑定到adodc1上,并设定表格的状态,要怎么做呢?我刚学vb,谢谢大家了,改了一天程序了,怎么都出不来,各位帮帮忙啊~! 展开
2个回答
展开全部
不用绑定,用代码就可以了。不要将adodc1与datagrid1绑定。
Option Explicit
Public conn As New ADODB.Connection
Public rs As ADODB.Recordset
Public sql As String
Public Sub connserver()
Set conn = New Connection
conn.ConnectionString = "Driver=;server=127.0.0.1,7788;uid=sa;pwd=admin;database=db_goods"
conn.ConnectionTimeout = 10
conn.Open
End Sub
Private Sub Command1_Click()
Adodc1.ConnectionString = conn
Adodc1.RecordSource = "select * from tb_bmxx order by bmxx_id"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Refresh
End Sub
Private Sub Form_Load()
Call connserver
End Sub
Option Explicit
Public conn As New ADODB.Connection
Public rs As ADODB.Recordset
Public sql As String
Public Sub connserver()
Set conn = New Connection
conn.ConnectionString = "Driver=;server=127.0.0.1,7788;uid=sa;pwd=admin;database=db_goods"
conn.ConnectionTimeout = 10
conn.Open
End Sub
Private Sub Command1_Click()
Adodc1.ConnectionString = conn
Adodc1.RecordSource = "select * from tb_bmxx order by bmxx_id"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
DataGrid1.Refresh
End Sub
Private Sub Form_Load()
Call connserver
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询