首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

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

2012-01-19 
怎样提取查询结果中每个子段的内容具体的代码是这样的:DimidAsStringRequest( userid )DimstrAsString

怎样提取查询结果中每个子段的内容
具体的代码是这样的:
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()
之后怎样才能提取到各个字段的内容?

[解决办法]
dr.GetString() 等方法
参数是字段索引值
[解决办法]
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
[解决办法]
比如说:username是表中的一个字段,
那么写法就是:dim strUsername as string = dr(“username”).ToString() & " "

热点排行