如何将多个语句添加到 DataGridView 数据源
本文关键字:添加 DataGridView 数据源 语句 | 更新日期: 2023-09-27 18:33:11
在系统中,dt获取网址,我把它们放到getco....函数在那里我调用一个 sql 语句,然后,我将其添加到 gridview 数据源。但它会获取最后一个 url 的项目,因此它会覆盖。我该如何解决?
for (int i = 0; i < dt.Rows.Count; i++)
{
row = dt.Rows[i];
GridView1.DataSource = db.getComboxedCombinedRSS( row[0].ToString());
}
GridView1.DataBind();
public DataSet getComboxedCombinedRSS(string url)
{
//SQL string to count the amount of rows within the OSDE_Users table
//string sql = "SELECT [RSS_Title], [RSS_ID], R.Syndication, R.Category FROM RSS AS R INNER JOIN CombinedFeeds AS C ON C.URL = R.URL WHERE C.Name='" +name+" ' ORDER BY RSS_Date desc";
string sql="SELECT top 30 [RSS_Title], [RSS_ID], Syndication, Category FROM RSS where URL= '"+url+"' order by RSS_DATE";
SqlDataAdapter adapt = new SqlDataAdapter(sql, Connect());
DataSet ds = new DataSet();
adapt.Fill(ds);
// result of query filled into datasource
adapt.Dispose();
closeConnection();
return ds;
}
DataSet ds = new DataSet();
for (int i = 0; i < dt.Rows.Count; i++)
{
row = dt.Rows[i];
db.getComboxedCombinedRSS( row[0].ToString(), ds);
}
GridView1.DataSource = ds;
GridView1.DataBind();
public void getComboxedCombinedRSS(string url, DataSet ds)
{
//SQL string to count the amount of rows within the OSDE_Users table
//string sql = "SELECT [RSS_Title], [RSS_ID], R.Syndication, R.Category FROM RSS AS R INNER JOIN CombinedFeeds AS C ON C.URL = R.URL WHERE C.Name='" +name+" ' ORDER BY RSS_Date desc";
string sql="SELECT top 30 [RSS_Title], [RSS_ID], Syndication, Category FROM RSS where URL= '"+url+"' order by RSS_DATE";
SqlDataAdapter adapt = new SqlDataAdapter(sql, Connect());
adapt.Fill(ds);
// result of query filled into datasource
adapt.Dispose();
closeConnection();
}