问题描述
- 新手求教 请大家帮忙看下源码
- ------------------------DAL------------------------------------------------------------
public List select(int UserID)
{
//初始化数据库连接对象
DateAccessLaye dbmyfile = new DateAccessLaye();
//初始化myfilemodel对象的集合实例
DataTable dsmf = dbmyfile.GetDataTable(""SELECT TitleFSizeCheckcodeUploadtime 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);** 报“未将对象引用设置到对象的实例”的错
解决方案
很多可能性,要调试才知道。
解决方案二:
没人帮忙看一下吗,关于list泛型存储数据在grideview上显示的问题,没办法显示,报“未将对象引用设置到对象的实例”的错
时间: 2024-09-13 04:43:42