Click here to Skip to main content
16,010,392 members
Home / Discussions / XML / XSL
   

XML / XSL

 
AnswerRe: How to get the datatype of an XML element using C# Pin
Denevers31-Mar-06 18:01
Denevers31-Mar-06 18:01 
Question"unable to establish connection to network" exception Pin
amresawy2-Mar-06 10:08
amresawy2-Mar-06 10:08 
QuestionBest way to feed xml Pin
krsouthern27-Feb-06 22:36
krsouthern27-Feb-06 22:36 
AnswerRe: Best way to feed xml Pin
imsathy2-Mar-06 19:26
imsathy2-Mar-06 19:26 
QuestionLooking for an XML Edit Control Pin
Nockawa27-Feb-06 10:00
Nockawa27-Feb-06 10:00 
Questionmatlab to xml coversion Pin
aksaqua26-Feb-06 22:13
aksaqua26-Feb-06 22:13 
QuestionXmlTextWriter C# invalid characters o;? Pin
rambo29826-Feb-06 8:37
rambo29826-Feb-06 8:37 
QuestionConvert xml dataset to string Pin
ironstrike125-Feb-06 12:47
ironstrike125-Feb-06 12:47 
Hi,

could anybody help with this?

I want to replicate this hard coded xml by drawing the data from a sql database.
I have had some sucess but I would like to omit "PR_Ref" entry from the resulting dataset,
but I do need it for the foreignkey/primarykey. I'm not sure if the string conversion is
correct either.

I need to read the resulting dataset to a string. This is the original hard coded bit:

______________________________________________________________________________________________


string xmlData;

xmlData = "<newdataset>";
xmlData += " <group>";
xmlData += " <name>Project 1";
xmlData += " <blockcolor>#ff0000";
xmlData += " <block>";
xmlData += " <href>activity.aspx?ActID=7";
xmlData += " <startdate>2005-04-01T00:00:00.0000000+01:00";
xmlData += " <enddate>2005-04-03T00:00:00.0000000+01:00";
xmlData += " <name>First part";
xmlData += " ";
xmlData += " <block>";
xmlData += " <href>activity.aspx?ActID=13";
xmlData += " <startdate>2005-04-06T00:00:00.0000000+01:00";
xmlData += " <enddate>2005-04-06T00:00:00.0000000+01:00";
xmlData += " <name>blah, blah";
xmlData += " ";
xmlData += " ";
xmlData += " <group>";
xmlData += " <name>Project 2";
xmlData += " <blockcolor>#ff0000";
xmlData += " <block>";
xmlData += " <href>activity.aspx?ActID=14";
xmlData += " <startdate>2005-04-06T00:00:00.0000000+01:00";
xmlData += " <enddate>2005-04-09T00:00:00.0000000+01:00";
xmlData += " <name>blah, blah";
xmlData += " ";
xmlData += " <block>";
xmlData += " <href>activity.aspx?ActID=15";
xmlData += " <startdate>2005-04-06T00:00:00.0000000+01:00";
xmlData += " <enddate>2005-04-09T00:00:00.0000000+01:00";
xmlData += " <name>blah";
xmlData += " ";
xmlData += " ";

xmlData += "";


______________________________________________________________________________________________

This is my attempt

____________________________________________________________________________________________


DataSet myds = new DataSet();
OleDbDataAdapter myGroupAdapter;
OleDbDataAdapter myBlockAdapter;
DataColumn primaryKey = new DataColumn();
DataColumn ForeignKey = new DataColumn();
OleDbConnection myConn = new OleDbConnection("Provider=SQLOLEDB.1; Persist Security Info=False; Data Source=xxx; Initial Catalog=xxx;User ID=xx;Password=xxxxxx;");
myGroupAdapter = new OleDbDataAdapter("select PR_NAME, blockcolor, PR_Ref from PM_PROJECT", myConn);
myBlockAdapter = new OleDbDataAdapter("Select href, Sub_Start, Sub_End, Sub_Name, PR_Ref from SUBTASK", myConn);
myGroupAdapter.Fill(myds, "group");
myBlockAdapter.Fill(myds, "block");
primaryKey = myds.Tables["group"].Columns["PR_Ref"];
ForeignKey = myds.Tables["block"].Columns["PR_Ref"];
DataRelation relation = new DataRelation("group", primaryKey, ForeignKey);
relation.Nested = true;
myds.Relations.Add(relation);

string xmlData = Convert.ToString((DataSet)myds);//not sure if this bit works


//I tested it with this:

myds.WriteXml("TestXML.txt")

___________________________________________________________________________________________

This was the resulting output


<newdataset>
<group>
<pr_name>Test Project
<blockcolor>#ff0000
<pr_ref>1
<block>
<href>activity.aspx?ActID=7
<sub_start>2006-02-02T00:00:00+00:00
<sub_end>2006-02-03T00:00:00+00:00
<sub_name>Start Test
<pr_ref>1

<block>
<href>activity.aspx?ActID=7
<sub_start>2006-02-03T00:00:00+00:00
<sub_end>2006-02-05T00:00:00+00:00
<sub_name>second sub for
<pr_ref>1

<block>
<href>activity.aspx?ActID=7
<sub_start>2006-02-03T00:00:00+00:00
<sub_end>2006-02-07T00:00:00+00:00
<sub_name>3rd test
<pr_ref>1


<group>
<pr_name>second Test
<blockcolor>#ff0000
<pr_ref>2
<block>
<href>activity.aspx?ActID=7
<sub_start>2006-02-01T00:00:00+00:00
<sub_end>2006-02-08T00:00:00+00:00
<sub_name>first/second
<pr_ref>2





Sorry the post is so long. Does anybody have any ideas??

Thanks

Ironstrike
AnswerRe: Convert xml dataset to string Pin
ironstrike125-Feb-06 12:49
ironstrike125-Feb-06 12:49 
QuestionXSD Validation Pin
Al Ortega25-Feb-06 5:21
Al Ortega25-Feb-06 5:21 
QuestionConversion of Excel Worksheet Data in to XML file Format Pin
winpoorni23-Feb-06 17:58
winpoorni23-Feb-06 17:58 
QuestionWatermark Pin
sreejith ss nair23-Feb-06 2:38
sreejith ss nair23-Feb-06 2:38 
AnswerRe: Watermark Pin
George L. Jackson24-Feb-06 1:07
George L. Jackson24-Feb-06 1:07 
QuestionXSD information in resx file Pin
sumit malik23-Feb-06 0:24
sumit malik23-Feb-06 0:24 
QuestionXmlDocument.NameTable vs namespaces Pin
chricla23-Feb-06 0:14
chricla23-Feb-06 0:14 
AnswerRe: XmlDocument.NameTable vs namespaces Pin
Douglas Troy3-Mar-06 6:47
Douglas Troy3-Mar-06 6:47 
QuestionPlease help - a question on XPath... Pin
Tigger9922-Feb-06 3:04
Tigger9922-Feb-06 3:04 
AnswerRe: Please help - a question on XPath... Pin
George L. Jackson22-Feb-06 12:58
George L. Jackson22-Feb-06 12:58 
QuestionXML file corrupted and filled with spaces..Any Idea!!! Pin
FiDz20-Feb-06 0:34
FiDz20-Feb-06 0:34 
AnswerRe: XML file corrupted and filled with spaces..Any Idea!!! Pin
George L. Jackson21-Feb-06 13:47
George L. Jackson21-Feb-06 13:47 
GeneralRe: XML file corrupted and filled with spaces..Any Idea!!! Pin
FiDz21-Feb-06 22:24
FiDz21-Feb-06 22:24 
GeneralRe: XML file corrupted and filled with spaces..Any Idea!!! Pin
George L. Jackson22-Feb-06 18:02
George L. Jackson22-Feb-06 18:02 
GeneralRe: XML file corrupted and filled with spaces..Any Idea!!! Pin
FiDz26-Feb-06 1:51
FiDz26-Feb-06 1:51 
QuestionHelp on MS Word 2003 XML Pin
ted_92119-Feb-06 15:27
ted_92119-Feb-06 15:27 
AnswerRe: Help on MS Word 2003 XML Pin
Douglas Troy3-Mar-06 6:32
Douglas Troy3-Mar-06 6:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.