2012-05-03 2 views
0

시스템에서 dt가 url을 가져오고 거기에 getco .... 함수를 넣은 다음 SQL statment를 호출하여 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

UR 루프가 덮어 쓰기된다. 핸들 그 – nawfal

+0

어떻게 처리 할 수 ​​있습니까? – leventkalay92

+0

leventkalay92만이 그렇게 할 수 있습니다.) 메커니즘은 무엇이되어야합니까? 각 결과 집합을 dgv에 추가 하시겠습니까? 처음 만 지켜라. 몇 가지를 지키고 나머지는 무시하십시오. 당신은 단지 문제가 u를 직면, 요구 사항을 말한 적이있다 .. – 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 편집을 시도하십시오 –

관련 문제