求教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=intPdIdrd=cmd.ExecuteReader()Dim s1 As StringDim s2 As String s1=rd("pdid").ToStrings2=rd("pdname")
[解决办法]
try:
- VB.NET code
If rd.read() then s1=rd("pdid").ToString s2=rd("pdname")end if