Form1: private sub Command1_Click() Form2.sqlXZ="select * from <表名> where <表名>.ID=" & txtID.Text & "" Form2.Show End SubForm2:定义一个Pulbic 变量 sqlXZ private sub Form_Load() ....adoQuery.RecordSource = sqlXZ adoQuery.Refresh End sub
1, .ConnectionString =?? 2,可能数据源错误 3,sqlXZ = "select * from <表名> where <表名>.ID=" & txtID.Text 这时ID一定得是数字型的,如果你定义为字符串,应该加引号
你的SQLXZ 不对啊! 要么 sqlXZ = "select * from <表名> where <表名>.ID='" & txtID.Text & "'" 要么 sqlXZ = "select * from <表名> where <表名>.ID=" & txtID.Text
要么 sqlXZ = "select * from <表名> where <表名>.ID='" & txtID.Text & "'" 要么 sqlXZ = "select * from <表名> where <表名>.ID=" & txtID.Text
1、可能是ODBC数据源配置错误,需要重新配置 2、sqlXZ = "select * from <表名> where <表名>.ID=" & txtID.Text & "" 中 如果ID字段为整型或长整型则为: sqlXZ = "select * from <表名> where <表名>.ID=" & clng(txtID.Text) 如果ID字段为字符型则为: sqlXZ = "select * from <表名> where <表名>.ID='" & trim$(txtID.Text) & "'" 3、DataGrid的DataSource属性可以通过代码实现: Set DataGrid1.DataSource=adoQuery
private sub Command1_Click()
Form2.sqlXZ="select * from <表名> where <表名>.ID=" & txtID.Text & ""
Form2.Show
End SubForm2:定义一个Pulbic 变量 sqlXZ
private sub Form_Load()
....adoQuery.RecordSource = sqlXZ
adoQuery.Refresh
End sub
2,可能数据源错误
3,sqlXZ = "select * from <表名> where <表名>.ID=" & txtID.Text
这时ID一定得是数字型的,如果你定义为字符串,应该加引号
要么
sqlXZ = "select * from <表名> where <表名>.ID='" & txtID.Text & "'"
要么
sqlXZ = "select * from <表名> where <表名>.ID=" & txtID.Text
sqlXZ = "select * from <表名> where <表名>.ID='" & txtID.Text & "'"
要么
sqlXZ = "select * from <表名> where <表名>.ID=" & txtID.Text
2、sqlXZ = "select * from <表名> where <表名>.ID=" & txtID.Text & ""
中
如果ID字段为整型或长整型则为:
sqlXZ = "select * from <表名> where <表名>.ID=" & clng(txtID.Text)
如果ID字段为字符型则为:
sqlXZ = "select * from <表名> where <表名>.ID='" & trim$(txtID.Text) & "'"
3、DataGrid的DataSource属性可以通过代码实现:
Set DataGrid1.DataSource=adoQuery
adoQuery.CommandType = adCmdText
sqlXZ = "select * from <表名> where <表名>.ID=" & txtID.Text & ""
adoQuery.RecordSource = sqlXZ
adoQuery.Refresh这样写是不够的,还应当创立一个Recordset集,"set rst=adoQuery.execute",并设置为DataGrid的Datasource
我已经调试通过了,回答对的我都会给分。错的也有分,不过少点了,鼓励为主嘛,呵呵……可是又碰上新问题了:
1.sqlXZ = "select * from <表名> where <表名>.ID=" & (txtID.Text) & "这句语句行不通呢(不管ID是整型还是文本型的)?那些单引号,双引号有些什么用呢?我想很多人都有同样的疑问吧。2.如果我的条件很多,比如还要让年龄=20(年龄是整型),让出生日期=81-11-11(出生日期是日期型),让姓名=张三(姓名是文本型)。要把所有的条件都写在一条SQL语句里,该怎么写?分行写怎么写(是不是加&_)?
Form1.Data1.RecordSource = "select " & biaoxiang & " from t_s,t_g where t_s.ID=t_g.ID and t_s.name=t_g.name and (" & Combo1.Text & "" & Combo2.Text & "'" & Text1.Text & "') "
Form1.sqlstr = "select " & biaoxiang2 & " from t_s,t_g where t_s.ID=t_g.ID and t_s.name=t_g.name and (" & Combo1.Text & "" & Combo2.Text & "'" & Text1.Text & "') "
Form1.Data1.Refresh
to new2:用and连接,如上。
sqlXZ = "select * from <表名> where <表名>.ID=" & CInt(txtID.Text)
2.条件多时这样写:
"... where ID=" & CInt(txtID.Text) & " And Name='" & _
txtName.Text & "' And Age=" & _
txtAge.Text