simplerMan
simplerMan
采纳率50%
2015-04-15 10:24 阅读 1.5k

新手求教 请大家帮忙看下源码

------------------------DAL------------------------------------------------------------
public List select(int UserID)
{
//初始化数据库连接对象
DateAccessLaye dbmyfile = new DateAccessLaye();
//初始化myfilemodel对象的集合实例
DataTable dsmf = dbmyfile.GetDataTable("SELECT Title,FSize,Checkcode,Uploadtime FROM myfile WHERE UserID=" + UserID);
List lmfm = new List();
myfilemodel mfmd = new myfilemodel();
foreach (DataRow dr in dsmf.Rows)
{
mfmd.Title = dr["Title"].ToString();
mfmd.FSize = (float)System.Convert.ToDouble(dr["FSize"].ToString());
mfmd.Checkcode = dr["Checkcode"].ToString();
mfmd.Uploadtime = Convert.ToDateTime(dr["Uploadtime"]);
lmfm.Add(mfmd);
}
return lmfm;
}
---------------------------------------------------------BLL-------------------------
public List select(int UserID)
{
myfiledal mf = new myfiledal();
return mf.select(UserID);
}
-------------------------------UI------------------------------------------------
protected void Button8_Click(object sender, EventArgs e)
{
int s = 0;
s = Convert.ToInt32(TextBox1.Text);
//GridView gv = new GridView();
//gv.DataSource = mf.select(s);
GridView1.DataSource = mf.select(s);
GridView1.DataBind();

}
    -------------------------DateAccessLaye----------------------------------------
     public DateAccessLaye()
    {
       #region 构造器
        //获取连接字符串
       constring =ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
       #endregion
    }

    public DataTable GetDataTable(string selectCommand)
{
    DataTable dt;
    //设置连接对象
    _sqlconnection = new SqlConnection(constring);
    //设置命令对象
    _sqlCmd = new SqlCommand();
    _sqlCmd.Connection = _sqlconnection;
    _sqlCmd.CommandType = CommandType.Text;
    _sqlCmd.CommandText = selectCommand;
    //初始化数据适配器
    _sqlconnection.Open();


    //DataTable DD = new DataTable();
    //int a = _sqlCmd.ExecuteNonQuery();

    _sqlAdp = new SqlDataAdapter(_sqlCmd);
    //初始化DataSet
    _sqlconnection.Close();
    dt = new DataTable();
    //填充DataSet
    _sqlAdp.Fill(dt);
    return dt;
}
    ---------------------------------------------------------------------------------
    数据在DAL层应该已经是获取了,但是一直对这一句:**GridView1.DataSource = mf.select(s);**    报“未将对象引用设置到对象的实例”的错
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • caozhy 从今以后生命中的每一秒都属于我爱的人 2015-04-15 17:49

    很多可能性,要调试才知道。

    点赞 1 评论 复制链接分享
  • simplerMan simplerMan 2015-04-15 13:44

    没人帮忙看一下吗,关于list泛型存储数据在grideview上显示的问题,没办法显示,报“未将对象引用设置到对象的实例”的错

    点赞 评论 复制链接分享

相关推荐