Home All Groups Group Topic Archive Search About
Author
20 Feb 2006 9:16 PM
Praveen
Hi All,
I was looking for a way to save the Different DataTables in a dataset as
differnt XML files. The WriteXML function is for Dataset and it saves all
the dataTables into one file. Is there any thing ready made.

Thanks in advance,
Praveen

Author
20 Feb 2006 9:35 PM
vinu
Praveen

No readymade method to save tables in dataset as individual xml file
DataTable has WriteXML method. Here is sample code written in .net 2 . To
get all the tables in dataset use for each statement and loop through
DataTable collection in DataSet

SqlCommand cmd = new SqlCommand();
            SqlConnection con = new SqlConnection();
            DataSet ds = new DataSet();

            SqlDataAdapter adap = new SqlDataAdapter();
            SqlDataReader rdr ;

            con.ConnectionString =
@"server=.;database=AdventureWorks;uid=xx;pwd=xx";
            con.Open();
            cmd.Connection = con;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = @"select LocationID,Name as LocNAme from
Production.Location";
            adap.SelectCommand = cmd;
            adap.Fill(ds, "ER");
            ds.Tables[0].WriteXml(@"c:\t.xml");

Vinu


Show quote
"Praveen" <praveen@newsgroup.nospam> wrote in message
news:OtxHZLmNGHA.1216@TK2MSFTNGP14.phx.gbl...
> Hi All,
> I was looking for a way to save the Different DataTables in a dataset as
> differnt XML files. The WriteXML function is for Dataset and it saves all
> the dataTables into one file. Is there any thing ready made.
>
> Thanks in advance,
> Praveen
>
Author
21 Feb 2006 3:39 PM
Praveen
Hi Vinu,
I dont find WriteXml available at the dataTable. I am using dotnet framework
v1.1.4322 is this only available in the .net version 2?

Thanks,
Praveen

Show quote
"vinu" <vinu.t.1***@googlemail.com> wrote in message
news:u6x54VmNGHA.2624@TK2MSFTNGP12.phx.gbl...
> Praveen
>
> No readymade method to save tables in dataset as individual xml file
> DataTable has WriteXML method. Here is sample code written in .net 2 . To
> get all the tables in dataset use for each statement and loop through
> DataTable collection in DataSet
>
> SqlCommand cmd = new SqlCommand();
>            SqlConnection con = new SqlConnection();
>            DataSet ds = new DataSet();
>
>            SqlDataAdapter adap = new SqlDataAdapter();
>            SqlDataReader rdr ;
>
>            con.ConnectionString =
> @"server=.;database=AdventureWorks;uid=xx;pwd=xx";
>            con.Open();
>            cmd.Connection = con;
>            cmd.CommandType = CommandType.Text;
>            cmd.CommandText = @"select LocationID,Name as LocNAme from
> Production.Location";
>            adap.SelectCommand = cmd;
>            adap.Fill(ds, "ER");
>            ds.Tables[0].WriteXml(@"c:\t.xml");
>
> Vinu
>
>
> "Praveen" <praveen@newsgroup.nospam> wrote in message
> news:OtxHZLmNGHA.1216@TK2MSFTNGP14.phx.gbl...
>> Hi All,
>> I was looking for a way to save the Different DataTables in a dataset as
>> differnt XML files. The WriteXML function is for Dataset and it saves all
>> the dataTables into one file. Is there any thing ready made.
>>
>> Thanks in advance,
>> Praveen
>>
>
>
Author
21 Feb 2006 6:54 PM
Cor Ligthert [MVP]
Praveen,

It is in Net 2.0, however than is still as a dataset written.

In fact it is nothing more than this.

I don't know what your language is, however I follow vinu

\\\
DataTable dt = ds.Tables[1].Copy(); //a copy of table 2.
DataSet ds2 = new DataSet();
ds2.Tables.Add(dt);
ds2.WriteXML(path);
///

Typed here in the message so watch typos

I hope this helps

Cor

Show quote
"Praveen" <praveen@newsgroup.nospam> schreef in bericht
news:%23gKszzvNGHA.916@TK2MSFTNGP10.phx.gbl...
> Hi Vinu,
> I dont find WriteXml available at the dataTable. I am using dotnet
> framework v1.1.4322 is this only available in the .net version 2?
>
> Thanks,
> Praveen
>
> "vinu" <vinu.t.1***@googlemail.com> wrote in message
> news:u6x54VmNGHA.2624@TK2MSFTNGP12.phx.gbl...
>> Praveen
>>
>> No readymade method to save tables in dataset as individual xml file
>> DataTable has WriteXML method. Here is sample code written in .net 2 . To
>> get all the tables in dataset use for each statement and loop through
>> DataTable collection in DataSet
>>
>> SqlCommand cmd = new SqlCommand();
>>            SqlConnection con = new SqlConnection();
>>            DataSet ds = new DataSet();
>>
>>            SqlDataAdapter adap = new SqlDataAdapter();
>>            SqlDataReader rdr ;
>>
>>            con.ConnectionString =
>> @"server=.;database=AdventureWorks;uid=xx;pwd=xx";
>>            con.Open();
>>            cmd.Connection = con;
>>            cmd.CommandType = CommandType.Text;
>>            cmd.CommandText = @"select LocationID,Name as LocNAme from
>> Production.Location";
>>            adap.SelectCommand = cmd;
>>            adap.Fill(ds, "ER");
>>            ds.Tables[0].WriteXml(@"c:\t.xml");
>>
>> Vinu
>>
>>
>> "Praveen" <praveen@newsgroup.nospam> wrote in message
>> news:OtxHZLmNGHA.1216@TK2MSFTNGP14.phx.gbl...
>>> Hi All,
>>> I was looking for a way to save the Different DataTables in a dataset as
>>> differnt XML files. The WriteXML function is for Dataset and it saves
>>> all the dataTables into one file. Is there any thing ready made.
>>>
>>> Thanks in advance,
>>> Praveen
>>>
>>
>>
>
>
Author
21 Feb 2006 11:53 PM
Praveen
Thanks Cor,
The code below would work but there is a copy of the dataTable. In my case
the data would be huge so I did not want to take a copy for obvious reasons.
If I dont find anything else then i would have to live with this.

Regards,
Praveen


Show quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:uD$3ZgxNGHA.2336@TK2MSFTNGP12.phx.gbl...
> Praveen,
>
> It is in Net 2.0, however than is still as a dataset written.
>
> In fact it is nothing more than this.
>
> I don't know what your language is, however I follow vinu
>
> \\\
> DataTable dt = ds.Tables[1].Copy(); //a copy of table 2.
> DataSet ds2 = new DataSet();
> ds2.Tables.Add(dt);
> ds2.WriteXML(path);
> ///
>
> Typed here in the message so watch typos
>
> I hope this helps
>
> Cor
>
> "Praveen" <praveen@newsgroup.nospam> schreef in bericht
> news:%23gKszzvNGHA.916@TK2MSFTNGP10.phx.gbl...
>> Hi Vinu,
>> I dont find WriteXml available at the dataTable. I am using dotnet
>> framework v1.1.4322 is this only available in the .net version 2?
>>
>> Thanks,
>> Praveen
>>
>> "vinu" <vinu.t.1***@googlemail.com> wrote in message
>> news:u6x54VmNGHA.2624@TK2MSFTNGP12.phx.gbl...
>>> Praveen
>>>
>>> No readymade method to save tables in dataset as individual xml file
>>> DataTable has WriteXML method. Here is sample code written in .net 2 .
>>> To get all the tables in dataset use for each statement and loop through
>>> DataTable collection in DataSet
>>>
>>> SqlCommand cmd = new SqlCommand();
>>>            SqlConnection con = new SqlConnection();
>>>            DataSet ds = new DataSet();
>>>
>>>            SqlDataAdapter adap = new SqlDataAdapter();
>>>            SqlDataReader rdr ;
>>>
>>>            con.ConnectionString =
>>> @"server=.;database=AdventureWorks;uid=xx;pwd=xx";
>>>            con.Open();
>>>            cmd.Connection = con;
>>>            cmd.CommandType = CommandType.Text;
>>>            cmd.CommandText = @"select LocationID,Name as LocNAme from
>>> Production.Location";
>>>            adap.SelectCommand = cmd;
>>>            adap.Fill(ds, "ER");
>>>            ds.Tables[0].WriteXml(@"c:\t.xml");
>>>
>>> Vinu
>>>
>>>
>>> "Praveen" <praveen@newsgroup.nospam> wrote in message
>>> news:OtxHZLmNGHA.1216@TK2MSFTNGP14.phx.gbl...
>>>> Hi All,
>>>> I was looking for a way to save the Different DataTables in a dataset
>>>> as differnt XML files. The WriteXML function is for Dataset and it
>>>> saves all the dataTables into one file. Is there any thing ready made.
>>>>
>>>> Thanks in advance,
>>>> Praveen
>>>>
>>>
>>>
>>
>>
>
>
Author
22 Feb 2006 5:23 AM
Kevin Yu [MSFT]
Hi Praveen,

I agree with Cor that we have to make a copy of it and add the copy to
another DataSet. Or we'll have to detach the DataTable from the origianl
DataSet, which would affect that DataSet.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
Author
22 Feb 2006 10:34 AM
Praveen
Hi Kevin,
I am ok if I can detach the DataTable from the initial DataSet and attach to
a new DataSet. In the specific case where I am using this it does not pose
any problems as i would anyway discard the original DataSet.

could you please let me know how to detach a dataTable from one dataset and
attach to another. Also what would happen of the schema that I would have
imported to the previous dataset. would that also be moved to the new
DataSet ?

Thanks in advance,
Praveen


Show quote
"Kevin Yu [MSFT]" <v-k***@online.microsoft.com> wrote in message
news:HqNjvA3NGHA.3052@TK2MSFTNGXA01.phx.gbl...
> Hi Praveen,
>
> I agree with Cor that we have to make a copy of it and add the copy to
> another DataSet. Or we'll have to detach the DataTable from the origianl
> DataSet, which would affect that DataSet.
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>
Author
22 Feb 2006 11:29 AM
Cor Ligthert [MVP]
Praveen,

I hope you don't mind that I answer this.

I had it first as sample with the remove

ds.Tables.Remove(dt);
or
ds.Tables.RemoveAt(0);

What I don't know is if the relations will than be removed as well, that was
the reason I did not give it you direct. (If you have no relations than that
is of course not important)

Adding it again will than be
ds.Tables.Add(dt);

(be aware that it will be added at the end then).

I hope this helps,

Cor

AddThis Social Bookmark Button