该方法共有5个重载 
public bool GetSingle(string columnName,out int result)
 
public bool GetSingle(string columnName, out string result)
 
public bool GetSingle(string columnName, out decimal result)
 
public bool GetSingle(string columnName, out bool result)
 
public bool GetSingle(string columnName, out DateTime result)
 
使用时注意 首先需要设置ID号主键才可以
 
示例代码     
 
        Student s = new Student();
        DataTable dt = s.GetList(-1, 0);       
        for (int index = 0; index < dt.Rows.Count; index++)
        {
            int Sid = Convert.ToInt32(dt.Rows[index]["ID"]);
 
            s.ID = Sid;
            int Age;
            if (s.GetSingle(EnumStudent.Age.ToString(), out Age))
            { Response.Write(string.Format("{0}的age是{1}<br>", dt.Rows[index]["username"].ToString(), Age)); }
            else
            { Response.Write(string.Format("{0}的age获取失败<br>", dt.Rows[index]["username"].ToString())); }
 
            s.New();
            s.ID = Sid;
            DateTime AddTime;
            if (s.GetSingle(EnumStudent.AddTime.ToString(), out AddTime))
            { Response.Write(string.Format("{0}的AddTime是{1}<br>", dt.Rows[index]["username"].ToString(), AddTime)); }
            else
            { Response.Write(string.Format("{0}的AddTime获取失败<br>", dt.Rows[index]["username"].ToString())); }
 
            s.New();
            s.ID = Sid;
            decimal Height;
            if (s.GetSingle(EnumStudent.Height.ToString(), out Height))
            { Response.Write(string.Format("{0}的Height是{1}<br>", dt.Rows[index]["username"].ToString(), Height)); }
            else
            { Response.Write(string.Format("{0}的Height获取失败<br>", dt.Rows[index]["username"].ToString())); }
        }
  
  
  
数据结构


执行结果



Leave a Reply