简体   繁体   English

如何将多个语句添加到DataGridView数据源

[英]How can I add multiple statements to DataGridView DataSource

In the system dt gets urls and I put them to getco.... function in there I call a sql statment then, I add it to gridview data source. 在系统dt中获取url,然后将它们放到getco ....函数中,在其中调用sql语句,然后将其添加到gridview数据源中。 But it gets last url's items so it overrides. 但是它会获取最后一个url的项目,因此它将被覆盖。 How can i solve it? 我该如何解决?

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

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以在不使用DataSource属性的情况下在DataGridView中添加DataTable吗 - Can I add DataTable in DataGridView without using DataSource property 如何将复选框添加到绑定到数据源的datagridview? - how to add a checkbox to a datagridview that is bound to a datasource? 如何使用数据源在datagridview中添加列总和 - How to add sum of columns in datagridview with datasource 如何手动将数据添加到dataGridView? - How can I manually add data to a dataGridView? 如何将一行添加到DataGridView? - How can I add one row to a DataGridView? 我如何 select 多个表到 datagridview? - How can i select multiple table to datagridview? 如何使用数据源绑定将数组字段映射到WinForms DataGridView中的多个列? - How do I map an array field to multiple columns in a WinForms DataGridView using a DataSource binding? 我如何将datagridview数据源转换为BindingListView(Equin.ApplicationFramework.BindingListView) - How Can i Convert datagridview datasource to BindingListView (Equin.ApplicationFramework.BindingListView) 对于使用“ DataGridView”的Windows窗体应用程序,如何检查数据源中的值并更改单独单元格的颜色? - For a Windows Forms Application using `DataGridView`, how can I check a value in my DataSource and change the color of a separate cell? 如何组合来自两个通用列表的数据并将该合并分配为 DataGridView 的数据源? - How can I combine data from two generic lists and assign that amalgamation as the datasource of a DataGridView?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM