40分发个简单的啦
DAL层:
public DataSet Select1()
{
string sql = "select * from newclass";
SqlHelper help = new SqlHelper();
return help.run(sql, CommandType.Text, null);
}
SQLHelper:
public DataSet run(string cmdName, CommandType cmdType, SqlParameter[] Sqlparams)
{
myConnection = new SqlConnection(ConfigurationManager.AppSettings["SQLCONNECTIONSTRING"].ToString());
SqlCommand cmd = new SqlCommand(cmdName, myConnection);
cmd.CommandType = cmdType;
if(Sqlparams != null)
{
foreach (SqlParameter sp in Sqlparams)
{
cmd.Parameters.Add(sp);
}
}
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
return ds;
}
页面我把DateSet绑定到dropdownlist上
public void Bind1()
{
DAL_NewClass dl = new DAL_NewClass();
DropDownList1.DataSource = dl.Select1().Tables[0].DefaultView;
DropDownList1.DataBind();
DropDownList1.DataTextField = "classname";
DropDownList1.DataValueField = "classid";
}
怎么显示不出数据呢?????显示 很多System.Data.DataRowView