Jul 25th, 2010, 01:41 AM
#1
Thread Starter
Hyperactive Member
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??
Jul 25th, 2010, 03:31 AM
#2
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
Jul 31st, 2010, 12:31 PM
#3
Thread Starter
Hyperactive Member
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.
Aug 1st, 2010, 09:08 AM
#4
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
Aug 1st, 2010, 12:36 PM
#5
Thread Starter
Hyperactive Member
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
Aug 2nd, 2010, 02:02 AM
#6
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
Aug 3rd, 2010, 11:37 AM
#7
Thread Starter
Hyperactive Member
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.
Aug 4th, 2010, 02:58 AM
#8
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
Aug 4th, 2010, 03:28 AM
#9
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
Forum Rules
Click Here to Expand Forum to Full Width