日期:2014-05-19  浏览次数:20519 次

在SQL查询后,获取某个字段的值
我代码是这么写的:
using   System;
using   System.Data;
using   System.Configuration;
using   System.Web;
using   System.Web.Security;
using   System.Web.UI;
using   System.Web.UI.WebControls;
using   System.Web.UI.WebControls.WebParts;
using   System.Web.UI.HtmlControls;
using   System.Data.SqlClient;

public   partial   class   _Default   :   System.Web.UI.Page  
{
        protected   void   Page_Load(object   sender,   EventArgs   e)
        {

        }
        protected   void   Button1_Click(object   sender,   EventArgs   e)
        {
                SqlConnection   Myconnection;
                SqlCommand   Mycommend;
                SqlDataReader   Myreader;
                SqlParameter   userParam;

                Myconnection   =   new   SqlConnection();
                Myconnection.ConnectionString   =   ConfigurationManager.ConnectionStrings[ "jwglConn "].ConnectionString;
                Mycommend   =   new   SqlCommand();
                Mycommend.CommandText   =   "select   *   from   user_tabl   where   UserName   =   @usr ";
                Mycommend.CommandType   =   CommandType.Text;
                Mycommend.Connection   =   Myconnection;

                userParam   =   new   SqlParameter();
                userParam.ParameterName   =   "@usr ";
                userParam.Value   =   TextBox1.Text.Trim();

                Mycommend.Parameters.Add(userParam);

                Mycommend.Connection.Open();
                Myreader   =   Mycommend.ExecuteReader();
                if   (!Myreader.Read())   return;  
                TextBox2.Text   =   Myreader[ "Psw "].ToString;//这儿有问题,提示:无法将方法组“tostring "转换为非委托类型 "sting "  
                Myreader   =   Mycommend.ExecuteReader(CommandBehavior.CloseConnection);
                Mycommend.Dispose();
                Myconnection.Dispose();
        }
}
我想通过字段名称来获取字段值,问题在那,该怎么写,请各位帮忙,谢谢了

------解决方案--------------------
TextBox2.Text = Myreader[ "Psw "].ToString();