SQL SERVER的数据库你应该会吧,这里就不说了。 dim db as new adodb.connection dim rs as new adodb.recordset dim str1 as string
db.open 数据库链接串 str1=select * from stu_info where stu_id='& txt1.text & ' rs.open str1,db,1 if rs.recordcount=0 then msgbox 没有记录! rs.close exit sub endif txt2.text=rs.fields(stu_name).value rs.close db.close
注意一下数据表中的字段stu_id的数据类型 str=select * from stu_info where stu_id='&txt1.text&' 写法是正确的
要想在txt2中显示查询的结果,首先要打开记录集 假设数据库连接对象为conn,记录集对象为rs则打开记录集语句为 rs.open str,conn,adopenkeyset,adlockoptimistic if rs.RecordCount0 then txt2.Text=rs.Fields(stu_name).Value end if
delcare @number int declare @course nvarchar(30) --for example select @number=number,@course=course from choice where studentnumber = '20100001' print @number print @course go
如果一定要print,那么这样吧: delcare @number int declare @course nvarchar(30) --for example select @number=number,@course=course from choice where studentnumber = '20100001' print @number print @course 这是楼上的朋友的劳动成果,望勿见怪
如果一定要PRINT全部的,那么用游标吧:
declare @info varchar(200) declare @curs cursor set @curs=cursor scroll dynamic for select 'number='+convert(varchar(20),number)+'; course='+convert(varchar(20),course) from choice where sex='F' open @curs fetch next from @curs into @info while(@@fetch_status=0) begin print @info fetch next from @curs into @info end