Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
Im getting started with XML and I want to use it to hold configuration for my website. I know xml is a supported datasource just as SQL or OLEDB or Oracle. is it possible to load an XML document as a datasource and query against it using SQL commands? Ive read that there is the Xpath classes but I would prefer to use sql commands if possible since that is what im most familiar with. any suggestions would be appreciated. thanks.
Posted

After loading the XML into a dataset you can use the dataset in the same way as any other dataset. Only possible difference is that I dont think it is possible to create a TypedDataset, but I'm not sure about that, havent tried it yet ;).

 

To use XPath and other XML tricks, you have to load it as an XMLDocument, not in a dataset.

Nothing is as illusive as 'the last bug'.
Posted

I would like to know this too. Is it posible to Query a DataSet.

 

Say I have a dataSet that contains an entire Database table. Would it posible to query the dataset with a

 

SELECT name

FROM employee ( or whatever your datatable is called )

WHERE ID=@ID

Posted

You can use select statements on a DataTable. The DataTable object has a select method that allows you to give a SQL style WHERE clause to select specific records from that DataTable. I dont believe you can use JOINs or combine records from several tables like SQL can.

 

Here is an example of the way I used a DataSet. The DataTables are added to the DataSet during creation of the form.

 

Declaration of the DataTable, and adding it to the DataSet

private System.Data.DataTable dtKey;

this.dsIndex.Tables.AddRange(new System.Data.DataTable[] {
this.dtKey,
this.dtFileMasks,
this.dtFileKeys,
this.dtFiles,
this.dtSettings});

If you don't add any tables before loading the XML file, I assume the DataSet creates the necessary DataTables (depending on the XmlReadMode). You can access them through the Tables property of the DataSet.

 

And a bit of code where I select some of the records in the DataTable.

//Get the selected item
ListViewItem objSelected = lvSearchIn.SelectedItems[0];
//get the filemask and folder name
string sFileMask = objSelected.SubItems[1].Text;
string sFolder = objSelected.Text;
//select the records
DataRow[] colSelectedRows = dtFileMasks.Select("Folder = '" + sFolder + "' and FileMask = '" + sFileMask + "'");
//delete all the records.
foreach (DataRow objRow in colSelectedRows)
{
   objRow.Delete();
}

Nothing is as illusive as 'the last bug'.
Posted

OK I have a strongly typed dataset from an XML file and Im trying to list all the nested items in a group that were pulled into the dataset. This is the code I am currently using, is there any better way anyone can think of doing this. this works fine but I was curious as to any other possibilites.

 

Example:

        Dim Group As dsControls.GroupRow
       Dim Item As dsControls._ItemRow
       For Each Group In siteSettings.Group.Select("ID='NameGroup'")
           For Each Item In Group.GetItemRows
               Response.Write("<b>" & Item.ID & "</b>:" & Item.Label & "<BR>")
               Response.Write("<b>" & Item.ID & "</b>:" & Item.Description & "<BR>")
               Response.Write("<b>" & Item.ID & "</b>:" & Item.TextBox & "<BR><BR>")
           Next
           Exit For
       Next

 

 

thanks

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...