日期:2014-05-18  浏览次数:20360 次

求教ado.net查询多个字段并取值的正确方法
定义了s1,s2两个string,想取得pd表中的pdid和pdname两个字段的值
在s1=rd("pdid").ToString这里错误,求正确写法
VB.NET code
conn=New OledbConnection(ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_enconn"))
sql="select pic,pdname from pd Where pdid=@pdid"
cmd=New OledbCommand(sql,conn)
conn.Open()
cmd.parameters.Add("@pdid",OledbType.Integer).Value=intPdId
rd=cmd.ExecuteReader()
Dim s1 As String
Dim s2 As String 
s1=rd("pdid").ToString
s2=rd("pdname")


------解决方案--------------------
try:

VB.NET code
If rd.read() then
  s1=rd("pdid").ToString
  s2=rd("pdname")
end if