Results 1 to 9 of 9

Thread: Load XML File Data

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Load XML File Data

    Is It Possible to Load XML File data into Adapter???
    Code:
    protected void Page_Load(object sender, EventArgs e)
        {
            
            DataSet ds1 = new DataSet();
            DataSet ds2 = new DataSet();
    
            if (!IsPostBack)
            {
                
                ds1.ReadXml("C:\\Users\\indel_intern96\\Desktop\\SONIA FOLDER\\sonia1.xml");
                OracleDataAdapter da = new OracleDataAdapter();
                da.Fill(ds2, 0, 4,"Table1");
                GridView1.DataSource = ds1;
                GridView1.DataBind();
                GridView2.DataSource = ds2;
                GridView2.DataBind(); 
            }
        }
    Cz in my above when i executed,I m getting the error -- VALUE cannot be null. Cz da is null. SO plz help me out.


    If Not Possible to Load XML file Data into Adapter,then wats the alternative way to do??

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Load XML File Data

    Hey,

    Part of the problem is that you are using ds2 to Fill da, but you are loading the XML into ds1.

    I don't think this is what you intended to do, is it?

    Gary

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Re: Load XML File Data

    Hi Gep,Wat exactly I want is Suppose in ds1,I have 10 Rows,In Ds2 I want to copy the First 5 Rows.I want to do just dat!! But Not able to find the solution.

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Load XML File Data

    Ok, but this is different from what you have talked about above.

    Your last post would indicate that you already have the DataTables populated. Once you have, then it is a simple matter of copying the DataRows between DataTables.

    Have a look here:

    http://support.microsoft.com/kb/308909

    For information on how this can be achieved.

    Gary

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Re: Load XML File Data

    Code:
    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataSet ds1 = new DataSet();
                DataSet ds3 = new DataSet();
                DataTable table_org = new DataTable();
                DataTable table_copy = new DataTable();
    
                ds1.ReadXml("C:\\Users\\indel_intern96\\Desktop\\SONIA FOLDER\\sonia1.xml");
                OracleDataAdapter da = new OracleDataAdapter();
    
                table_org = ds1.Tables[0];
                int iRowsCount;
                iRowsCount = table_copy.Rows.Count;
    
                for (int i = 0; i < table_org.Rows.Count; i++)
                {
                    table_copy.ImportRow(table_org.Rows[i]);
                }
                iRowsCount = table_copy.Rows.Count;
                ds3.Tables.Add(table_copy);
            }
    Earlier in iRowsCount=0, but after executin the for Loop,in iRowsCount=4. Rows are copied but not the row data.
    Code:
                for (int i = 0; i < table_org.Rows.Count; i++)
                {
                    table_copy.ImportRow(table_org.Rows[i]);
                }
    In fig,You can see what table_copy contains!!
    Attached Images Attached Images  

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Load XML File Data

    Hey,

    Have you set a breakpoint on this line:

    Code:
    table_copy.ImportRow(table_org.Rows[i]);
    Does it ever get hit?

    Gary

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Re: Load XML File Data

    hi Gep,Yes the statement is hit. Statement hit,dats y the 4 rows are inserted but only the rows are copied not the data.

  8. #8
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Load XML File Data

    Hey,

    The documentation for that method:

    http://msdn.microsoft.com/en-us/libr...importrow.aspx

    Suggests that it should pull across the current values of the row as well. I will do some digging and see what I can come up with.

    Gary

  9. #9
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Load XML File Data

    Try this one...

    Code:
    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataSet ds1 = new DataSet();
                DataSet ds3 = new DataSet();
                DataTable table_org ;
                DataTable table_copy ;
    
                ds1.ReadXml("C:\\Users\\indel_intern96\\Desktop\\SONIA FOLDER\\sonia1.xml");
                
    	//Copy the structure to the second table
                table_copy =table_org.clone();
    
                table_org = ds1.Tables[0];
                int iRowsCount;
                iRowsCount = table_copy.Rows.Count;
    
                for (int i = 0; i < table_org.Rows.Count; i++)
                {
                    table_copy.ImportRow(table_org.Rows[i]);
                   //Or use this method
                 //  table_copy.rows.add(table_org.Rows[i].toItemArray());
                }
                iRowsCount = table_copy.Rows.Count;
                ds3.Tables.Add(table_copy);
            }
    Please mark you thread resolved using the Thread Tools as shown

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width