为什么数据表返回零值

时间:2015-11-20 18:10:11

标签: c#

id正在运行,其记录存在于数据库中。在调试过程中,我发现dt.Count为零。为什么dt在这里返回零值?

类:

 public class UserGroup
{
    public int id { get; set; }
    public string name { get; set; }
    public int creator_id { get; set; }
    public DateTime date { get; set; }
    public DateTime? change_date { get; set; }
    public int? changer_id { get; set; }
    public int? deleted { get; set; }

    public UserGroup() { }

    public UserGroup (UserGroupDs.UserGroupRow row)
    {
        UserGroup group = new UserGroup();

        this.id = row.id;
        this.name = row.name;
        this.date = row.created_date;
        this.creator_id = row.creator_user_id;
        this.change_date = row.Ischanged_dateNull() ? null : (DateTime?)row.changed_date;
        this.changer_id = row.Ischanger_user_idNull() ? null : (int?)row.changer_user_id;
        this.deleted = row.IsdeletedNull() ? null : (int?)row.deleted;

    }
}

这是控制器:

public UserGroup ById(int id)
    {
        UserGroupDs.UserGroupDataTable dt = Dalc.Sel(id, null, 1);
        if (dt.Count < 1) return null; // 
        return new UserGroup(dt[0]);// it suppose to return this
    }

这里是Dalc函数

  public UserGroupDs.UserGroupDataTable Sel(int? id, string name, int mode)
    {
        UserGroupDs ds = new UserGroupDs();

        using (SqlConnection con = new SqlConnection(Global.Config.ConnStr))
        {

            SqlCommand cmd = new SqlCommand("spp_adm_userGroup_sel", con);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@id", id < 1 ? dbNull : id);
            cmd.Parameters.AddWithValue("@name", string.IsNullOrEmpty(name) ? dbNull : name.Trim());
            cmd.Parameters.AddWithValue("@mode", Convert.ToInt32(mode));

            FillDataSet(cmd, ds, new string[] { ds.UserGroup.TableName });

        }

        return ds.UserGroup;
    }

0 个答案:

没有答案