Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何向DataGridView数据源添加多条语句_C#_Data Binding_Datagridview_Datasource - Fatal编程技术网

C# 如何向DataGridView数据源添加多条语句

C# 如何向DataGridView数据源添加多条语句,c#,data-binding,datagridview,datasource,C#,Data Binding,Datagridview,Datasource,在系统中,dt获取URL,我将它们放入getco。。。。函数中,我调用一个sql语句,然后将其添加到gridview数据源中。但它会获取最后一个url的项,因此会覆盖。我怎样才能解决它 for (int i = 0; i < dt.Rows.Count; i++) { row = dt.Rows[i]; GridView1.DataSource = db.getComboxedCombinedRSS( row[0].ToString(

在系统中,dt获取URL,我将它们放入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;
}

你的循环正在覆盖它。只有leventkalay92才能做到这一点:机制应该是什么?是否将每个结果集添加到dgv?只保留第一个?保留一些,忽略其余的?您只告诉了您所面临的问题,而没有告诉要求..谢谢,但它没有添加第二个,因此else语句不起作用?RSS_ID是RSS_日期的主键吗?getcomboxed函数中有错误,它返回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();

}