ASP. NET数据库读取数据放到页面该怎么处理
DataSetdataset1=newDataSet();SqlDataAdaptercmad;stringSQLString="";stringconnectionSt...
DataSet dataset1 = new DataSet();
SqlDataAdapter cmad;
string SQLString = "";
string connectionString = "server=localhost;database=dp; uid=sa;pwd=123456";
//将连接字符串传入SqlConnection对象的构造函数中
SqlConnection mySqlConnection = new SqlConnection(connectionString);
mySqlConnection.Open();
SQLString = " select * from t_news where status=1";
cmad = new SqlDataAdapter(SQLString, connectionString);
cmad.Fill(dataset1,"t_news");
NewsList1.DataSource = dataset1.Tables["t_news"];
NewsList1.DataBind();
SQLString = " select * from t_news where status=2";
cmad = new SqlDataAdapter(SQLString, connectionString);
cmad.Fill(dataset1, "t_news");
NewsList2.DataSource = dataset1.Tables["t_news"];
NewsList2.DataBind();
mySqlConnection.Close();
这个代码是错的,第二个列表貌似把第一个和第二个的数据一起显示出来了。
怎么改,我犯了什么错? 展开
SqlDataAdapter cmad;
string SQLString = "";
string connectionString = "server=localhost;database=dp; uid=sa;pwd=123456";
//将连接字符串传入SqlConnection对象的构造函数中
SqlConnection mySqlConnection = new SqlConnection(connectionString);
mySqlConnection.Open();
SQLString = " select * from t_news where status=1";
cmad = new SqlDataAdapter(SQLString, connectionString);
cmad.Fill(dataset1,"t_news");
NewsList1.DataSource = dataset1.Tables["t_news"];
NewsList1.DataBind();
SQLString = " select * from t_news where status=2";
cmad = new SqlDataAdapter(SQLString, connectionString);
cmad.Fill(dataset1, "t_news");
NewsList2.DataSource = dataset1.Tables["t_news"];
NewsList2.DataBind();
mySqlConnection.Close();
这个代码是错的,第二个列表貌似把第一个和第二个的数据一起显示出来了。
怎么改,我犯了什么错? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询