------------------------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);** 报“未将对象引用设置到对象的实例”的错