vb查询按钮 代码
留下代码事例至少
2个查询条件
留下代码事例至少
2个查询条件
答案:你在vb的工程中 工程-引用 添加micfosoft activex data objects 2.5 library然后在你command1中添加入以下代码
Dim rs As New ADODB.Connection
Dim str As String
Dim re As New ADODB.Recordset
Dim strsql As String
str = "Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=GFDY2007;Data Source=20091103-1521"
'SQLOLEDB 为数据源 SQL server ;access等 这里是sql server, Password 为数据库登录密码 Persist Security Info=True不管,User ID为数据库登录名称
'Initial Catalog 为数据库名 ,Data Source 为机器名
rs.Open str
strsql = "select * from 表名" 'SQL查询语句"
re.Open strsql, str, 1, 3 '使用 Open 方法打开数据库中的一个表
if not re.eof then在这里添加你上面的代码
就是查询的那段
re.Close你试试看。。。对的话别忘记加分了
Private Sub querayInfo_Click() ' 查询功能
querySql = "select stuId as 学号,stuName as 姓名, 易做图 as 性别 , stu_xibuName as 系部,stu_className as 班级,status as 易做图面貌 ,tel as 手机号码,address as 家庭住址,Email as 电子邮件 , QQ from stu_info "
If queryStuId <> "" Then
querySql = querySql & " where stuId = '" & Trim(queryStuId.Text) & "'"
ElseIf queryStuName <> "" Then
querySql = querySql & " where stuName like '%" & Trim(queryStuName.Text) & "%'"
ElseIf cb_xibuName <> "" Then
querySql = querySql & " where stu_xibuName = '" & Trim(cb_xibuName.Text) & "'"
ElseIf cb_className <> "" Then
querySql = querySql & " where stu_className = '" & Trim(cb_className.Text) & "'"
End If
If queryStuId.Text = "" And queryStuName.Text = "" And cb_xibuName.Text = "" And cb_className.Text = "" Then
MsgBox "请输入查询条件"
End If
If Adodc1.Recordset.EOF Then
MsgBox "没有该毕业生的任何信息"
End If
Me.Adodc1.RecordSource = querySql
Adodc1.Refresh
Me.DataGrid1.ReBind
End Sub
上一个:Delphi,java,VB哪个比较好
下一个:请教VB的问题