2012-05-03 43 views
0

在系统中dt获取urls并将它们放到getco ....函数中,然后我调用sql语句,然后将其添加到gridview数据源。但它获取最后一个url的项目,因此它覆盖。我如何解决它?如何添加多个语句到DataGridView数据源

 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; 
} 
+0

乌尔循环覆盖它。处理 – nawfal

+0

我该如何处理? – leventkalay92

+0

只有leventkalay92可以做到这一点:)该机制应该是什么?将每个结果集添加到dgv?只保留第一个?保留一些,并忽略其余的?你只告诉我面临的麻烦,从来没有要求.. – nawfal

回答

0
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(); 

} 
+0

谢谢,但它不添加第二个,所以其他语句不起作用? – leventkalay92

+0

是RSS_ID - RSS_DATE的主键吗? –

+0

试试las编辑 –

相关问题