想用数据源控件绑定的办法显示一条记录的一个字段的值

解决方案 »

  1.   

    一条记录一个字段还用绑定嘛, 直接赋值
    不编辑用 Label ,
    需要编辑 TextBox
      

  2.   

    我觉得是在编辑列里只留下这个字段,在where里限制条件吧
      

  3.   

    public static string getFiled(string sql)
    {
    string str_field = String.Empty;
    SqlDataReader dr = DataAccess.ExcuteQuery(sql);
    while(dr.Read())
    {
    str_field = dr[0].ToString();
    }
    dr.Close();
    return str_field;
    }
      

  4.   

    public static SqlDataReader ExcuteQuery(string sql)
    {
    SqlCommand sqlcmd = new SqlCommand(sql,DBConnection);
    try
    {
    sqlcmd.Connection.Open();
    }
    catch(Exception ex)
    {
    throw new Exception("Error:ExcuteQuery()-->"+ex.Message);
    }
    finally
    {
    sqlcmd.Dispose();
    }
    return sqlcmd.ExecuteReader(CommandBehavior.CloseConnection);
    }
      

  5.   

    public static SqlConnection DBConnection
    {
    get
    {
    SqlConnection conn = null;
    try
    {
    conn = new SqlConnection(ConnectionString);
    }
    catch(Exception ex)
    {
    throw new Exception("Error:ExcuteQuery()-->"+ex.Message);
    }
    return conn;
    }
    }