您的位置:程序门 -> .net技术 -> vb.net



怎样提取查询结果中每个子段的内容


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


怎样提取查询结果中每个子段的内容[已结贴,结贴人:zhlxh1201]
发表于:2007-04-30 15:58:21 楼主
具体的代码是这样的:
dim   id   as   string   =   request( "userid ")
dim   str   as   string   =   "provider=msdaora.1;data   source=kksb;user   id=kksb;password=kksb2007; "
dim   conn   as   system.data.oledb.oledbconnection   =   new   system.data.oledb.oledbconnection(str)
dim   dr   as   system.data.oledb.oledbdatareader
conn.open()
dim   strsql   as   string   =   "select   *   from   t_user   where   userid= "   &   id
dim   comm   as   system.data.oledb.oledbcommand   =   new   system.data.oledb.oledbcommand(strsql,conn)
dr   =   comm.EXECutereader()
之后怎样才能提取到各个字段的内容?
发表于:2007-04-30 16:02:211楼 得分:10
dr.getstring()   等方法
参数是字段索引值
发表于:2007-04-30 16:15:592楼 得分:0
dr(t_user表的各字段).tostring()   &   " "
发表于:2007-04-30 16:22:003楼 得分:0
是不是可以将dr(username).tostring()直接赋给一个变量参数呢?
发表于:2007-04-30 16:24:014楼 得分:0
该回复于2007-12-21 19:30:59被管理员或版主删除
发表于:2007-04-30 16:33:465楼 得分:0
怎么用呀?
dr(t_user表的各字段).tostring()  
语法报错说:dr不是表达式
发表于:2007-04-30 16:46:436楼 得分:30
dim   id   as   string   =   request( "userid ")
                dim   str   as   string
                dim   connstr   as   string   =   数据连接语句
                dim   con   as   new   oledbconnection(connstr)
                dim   strsql   as   string   =   "select   *   from   t_user   where   userid= "   &   id
                dim   da   as   new   oledbdataadapter(strsql,   con)
                dim   ds   as   new   dataset
                try
                        con.open()
                        da.fill(ds)
                        'str=查询结果的第i行第i列
                        str   =   ds.tables(0).rows(i)(i).tostring().trim()
                catch   ex   as   exception
                        msgbox(ex.tostring())
                finally
                        con.close()
                end   try
发表于:2007-04-30 17:09:057楼 得分:20
比如说:username是表中的一个字段,
那么写法就是:dim   strusername   as   string   =   dr(“username”).tostring()   &   " "
发表于:2007-07-26 09:22:398楼 得分:0
问题解决了
用的方法是
str   =   ds.tables(0).rows(i)(i).tostring().trim()
多谢大家的帮忙!


快速检索

最新资讯
热门点击