100分求助!!!急!!!!!!!!!!!!!!! 我基本不太会VB,想问些比较简单的问题 我有三个TEXT控件,程序
代码中我把它们存成Text(i)数组.下面是我的读取access
数据库student表的
内容代码,我想根据这三个Text控件的输入来进行
查询,为什么不好用呢,兄弟们帮忙看一下,急死我了啊。!!! Private Sub Command5_Click() Dim
sqlString As String Dim S1 As String,S As String Dim i As Integer For i = 0 To 2 If Text1(i) <> " " Then Select Case i Case 0 S1 = "student.学号 = " & " '' " & Text1(i) & " '' " Case 1 S1 = "student.姓名 = " & " '' " & Text1(i) & " '' " Case 2 S1 = "student.性别 = " & " '' " & Text1(i) & " '' " End Select If S <> " " Then S = S & "AND " & S1 Else S = S1 End If End If Next i
sqlString = " SELECT * FROM student WHERE S " Adodc2.RecordSource =
sqlString Adodc2.Refresh End Sub 每次我运行时都告诉我至少有一个参数没有指定值,我都快疯了,Adodc指定了connectString,
属性中RecordSource 怎么写呢?写select * from student where s 不行吧,S它认识么?所以
属性中我都不知道写什么了,还有老
提示我的没指定值的问提,大哥们帮帮忙啊,帮我看看我这段程序啊,求求了 __________________________________________________________________________
sqlString = " SELECT * FROM student WHERE S " 改一下再试
sqlString = " SELECT * FROM student WHERE " & S __________________________________________________________________________ S应该等于什么的吧 应该是等于text1的
内容 你可以
加上= '' " & Text1(i) & " '' 试试 我也是菜鸟 又没做过 access 我做的也都不一样 不过你用的是文本框的话 应该不用写
分类事件吧 我用的是combo
Box 下拉
菜单 用了
分类可以 仅供参考 __________________________________________________________________________
sqlString = " SELECT * FROM student WHERE " & S __________________________________________________________________________ 先要学会自己调试,你设置一下断点,看看最终拼接成的字符串是否正确? 另外,尽量不要用拼接的方式组织
sql语句,很容易出错 __________________________________________________________________________ Private Sub Command5_Click() Dim
sqlString As String Dim S1 As String,S As String Dim i As Integer For i = 0 To 2 If Text1(i) <> " " Then Select Case i Case 0 S1 = "student.学号 = " & " '' " & Text1(i) & " '' " Case 1 S1 = "student.姓名 = " & " '' " & Text1(i) & " '' " Case 2 S1 = "student.性别 = " & " '' " & Text1(i) & " '' " End Select If S <> " " Then ''AND 前后给空格 S = S & " AND " & S1 Else S = S1 End If End If Next i ''S是变量单独分隔出来
sqlString = " SELECT * FROM student WHERE " & S Adodc2.RecordSource =
sqlString Adodc2.Refresh End Sub __________________________________________________________________________ 你这边拼接有问题: If S <> " " Then ''AND 前后给空格 S = S & " AND " & S1 Else S = S1 End If 如果这样拼接的话,最后出来的结果是:SELECT * FROM student WHERE AND student.学号 = XX AND student.姓名 = XX AND student.性别 = XX 建议这样来写:
sqlString = " SELECT * FROM student WHERE 1=1 " & S 在前面这样写: Select Case i Case 0 S1 = " AND student.学号 = " & " '' " & Text1(i) & " '' " Case 1 S1 = " AND student.姓名 = " & " '' " & Text1(i) & " '' " Case 2 S1 = " AND student.性别 = " & " '' " & Text1(i) & " '' " End Select __________________________________________________________________________ 建议这样来写:
sqlString = " SELECT * FROM student WHERE 1=1 " & S 在前面这样写: Select Case i Case 0 S1 = " AND student.学号 = " & " '' " & Text1(i) & " '' " Case 1 S1 = " AND student.姓名 = " & " '' " & Text1(i) & " '' " Case 2 S1 = " AND student.性别 = " & " '' " & Text1(i) & " '' " End Select S = S & S1 __________________________________________________________________________ 大哥们,我按你们的
方法都试了,还是不行呀,按你们的
方法改完后不
提示参数没指定了,但就是点
查询按钮没任何反映,ADODC2这个控件右面
属性窗口中的RcordSource写什么呢?空么?如果我也写带S的它就又
提示我参数没指定值。怎么办啊,我的兄弟们。。。。。 __________________________________________________________________________ Private Sub Command5_Click() Dim
sqlString As String Dim S1 As String,S As String Dim i As Integer For i = 0 To 2 If Text1(i) <> " " Then Select Case i Case 0 S1 = " AND student.学号 = " & " '' " & Text1(i) & " '' " Case 1 S1 = " AND student.姓名 = " & " '' " & Text1(i) & " '' " Case 2 S1 = " AND student.性别 = " & " '' " & Text1(i) & " '' " End Select S = S & S1 End If Next i
sqlString = " SELECT * FROM student WHERE 1=1 " & S Adodc2.RecordSource =
sqlString Adodc2.Refresh End Sub 再试试,如果不行,把断点设在Adodc2.RecordSource =
sqlString这上面,把
sqlString的值拿到
sql中去
查询一下。 __________________________________________________________________________ Private Sub Command5_Click() Dim
sqlString As String Dim S1 As String,S As String Dim i As Integer
sqlString = "SELECT * FROM student " ''请看下面的
sql写法,假设你有Text1,Text2,Text3 If Not Text1.Text = String.Empty Then
sqlString &= " Where "
sqlString &= "student.学号 = '' " & Text1.Text & " '' " End If If Not Text2.Text = String.Empty Then If Not Text1.Text = String.Empty Then
sqlString &= " And " Else
sqlString &= " Where " End If
sqlString &= "student.姓名 = '' " & Text2.Text & " '' " End If If Not Text3.Text = String.Empty Then If Not Text1.Text = String.Empty Or Not Text2.Text = String.Empty Then
sqlString &= " And " Else
sqlString &= " Where " End If
sqlString &= "student.性别 = '' " & Text3.Text & " '' " End If Adodc2.RecordSource =
sqlString Adodc2.Refresh End Sub __________________________________________________________________________ 我看到了,按你的
方法做设置断点调式时我看到的
sql语句的值是select * from student where student.学号= '' 111 ''(我输入111时
查询),这里要用trim么,还是数据类型能够不对,怎么读不出来呢?哥们你可以加我QQ么54219484,帮我帮到底吧,兄弟 __________________________________________________________________________ 我这里不能用QQ。 你这样做:表student.学号的类型是什么类型?如果是int的话,不用加‘’的,直接用;如果是string的话,那就要加‘’的,还有要用trim的。 先试试 __________________________________________________________________________ 都是文本类型的,没有INT型的,TRIM我应该怎么样加呢,加在哪?还有ADODC2右面面板上的RcoedSource
属性我怎么设置呢,里面也要写SELECT * FROM student WHERE 1=1 & S这个么,还是写什么? __________________________________________________________________________ DataGrid2的DataSource设为Adodc2。最后可将Adodc2的Visible设为True使之运行时可见。 我是说让你去
数据库看看它的类型。 __________________________________________________________________________ Text1.Text.trim __________________________________________________________________________ 我
数据库里设计的都是文本类型的,我看了。我问那个ADODC2右面
属性里该咋添呢?不是DATAGRID2
属性,ADODC2右面
属性里有个需要添写
sql语句的地方,添什么呢 __________________________________________________________________________ 在命令文本中输入:select * from student __________________________________________________________________________ 感觉你是在做毕业设计... __________________________________________________________________________ 哥们,问题
解决了,有一个控件名写错了,很感谢你对我的帮助,只恨不能给你更多的分,也感谢大家了,我记得的大家,下回我散分给大家 __________________________________________________________________________
原文链接:https://www.f2er.com/vb/263757.html