asp.net的ExecuteReader()方法的用法
usingSystem;usingSystem.Collections;usingSystem.Configuration;usingSystem.Data;usingS...
using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data.SqlClient;namespace exam{ public partial class test : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { SqlCommand cmd = DB.createSqlcommand("select * from denglu where id=1"); SqlDataReader sdr = cmd.ExecuteReader(); //string a = sdr.GetName(0); string a = Convert.ToString(sdr.GetValue(0));我想取出改行的id,但报错了 this.Label1.Text = a; } }} 上面这段代码有错,请问错在哪里?该怎样用ExecuteReader()从数据库中取出特定字段的值
展开
2个回答
展开全部
ExecuteReader()这只是一个方法啊,SqlCommand cmd = DB.createSqlcommand("select * from denglu where id=1"); 你觉得这错没?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
SqlConnection呢?
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader da = cmd.ExecuteReader();
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader da = cmd.ExecuteReader();
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询