2016-05-24 10 views
0

私はamazon Webサービスを使用するwinformアプリケーションで作業しています。まず、あなたがあなたからのDataTableを作成する必要があります。..xmlオブジェクトを使用してC#でdatagridviewをバインドする方法

private void btnRun_Click(object sender, EventArgs e) 
     { 
      if (CheckForInternetConnection()) 
       try 
       { 
        // Instantiate Amazon ProductAdvertisingAPI client 
        amazonClient = new AWSECommerceServicePortTypeClient(); 

        // prepare an ItemSearch request 
        request = new ItemSearchRequest(); 

        request.SearchIndex = "Books"; 
        request.Title = "The Life and Love of the Sea"; 
        request.ResponseGroup = new string[] { "Small" }; 

        itemSearch = new ItemSearch(); 
        itemSearch.Request = new ItemSearchRequest[] { request }; 
        itemSearch.AWSAccessKeyId = ConfigurationManager.AppSettings["accessKeyId"]; 
        itemSearch.AssociateTag = "AssociationTag"; 

        // send the ItemSearch request 
        response = amazonClient.ItemSearch(itemSearch); 
        // here i want to bind the datagridview with this xml response. 

       } 
       catch (Exception ex) 
       { 
        MessageBox.Show(ex.Message); 
       } 
      else 
       MessageBox.Show("No Internet Connection found"); 
     } 

答えて

0

を私がデータを取得するための要求をした、応答がXMLオブジェクトであるが、私はdatagridwiewと、このXML応答をバインドする方法を知らない、ここに私のコードがありますxmlデータを取得し、DataTableをgridViewにバインドします。

これは私がXMLファイルからデータテーブルを作成するために使用するコードです:

//This method return a dataTable created with your xml data 
public static DataTable getDataByRessource() 
    { 
     //Create the new xml document 
     XmlDocument xmlDoc = new XmlDocument(); 

     //Here you can load your file , i load it with the resources properties of my project 
     xmlDoc.LoadXml(Properties.Resources.TRADUCTION); 
     //This dataSet will contains your dataTable with your data 
     DataSet ds = new DataSet(); 
     //Parse the xml to a dataTable 
     XmlNodeReader xnr = new XmlNodeReader(xmlDoc); 
     ds.ReadXml(xnr); 

     //return your dataTable 
     return ds.Tables[0]; 
    } 

は今、あなたはこれだけのDataTableにあなたのGridViewのデータソースをバインドする必要があります。

EDIT:

はこちらをご覧ください、それはあなたが達成したいものを、おそらくです:http://www.midniteblog.com/?p=20

+0

実際に私は正確にXMLオブジェクトの –

+0

どのようなタイプの....私はXMLオブジェクトを持って、xmlファイルを持っていけませんか? (C#クラスまたは同等のもの) – Furtiro

+0

申し訳ありませんが、私はそれについてはわからない –

関連する問題