Connecting Tech Pros Worldwide Help | Site Map

Using 'LIKE' with XML Data

  #1  
Old August 29th, 2008, 12:35 PM
Jeff Gaines
Guest
 
Posts: n/a

I keep some notes in a small XML data file and would like to be able to
search them.

I am building a filter string:

filterString = string.Format("{0} '%{1}%'", "SELECT * FROM " + m_TableName
+ " WHERE FileName LIKE ", searchString);

When testing this produces:

"SELECT * FROM tblFileNotes WHERE FileName LIKE '%nero%'"

When I then call:

DataRow[] foundRows = dtTemp.Select(filterString);

I get the error:

Missing operand after 'tblFileNotes' operator.

The table name is correct as is the field name and the same query works
with an Access database. I have also used it without the 'LIKE' operator
and it produces all the records so it is able to find the file OK.

I have spent the morning on Google but most results relate to SQL
databases rather than an XML database.

Am I attempting the impossible? I could read all the records in and search
them but it would be good to filter them out if possible.

Many thanks.

--
Jeff Gaines Damerham Hampshire UK
All those who believe in psychokinesis raise my hand.
  #2  
Old August 29th, 2008, 12:55 PM
Martin Honnen
Guest
 
Posts: n/a

re: Using 'LIKE' with XML Data


Jeff Gaines wrote:
Quote:
>
I keep some notes in a small XML data file and would like to be able to
search them.
>
I am building a filter string:
>
filterString = string.Format("{0} '%{1}%'", "SELECT * FROM " +
m_TableName + " WHERE FileName LIKE ", searchString);
>
When testing this produces:
>
"SELECT * FROM tblFileNotes WHERE FileName LIKE '%nero%'"
>
When I then call:
>
DataRow[] foundRows = dtTemp.Select(filterString);
>
I get the error:
>
Missing operand after 'tblFileNotes' operator.
>
The table name is correct as is the field name and the same query works
with an Access database. I have also used it without the 'LIKE' operator
and it produces all the records so it is able to find the file OK.
>
I have spent the morning on Google but most results relate to SQL
databases rather than an XML database.
I don't see any XML in your post. Are you sure your question relates to
XML in the .NET framework? What type does dtTemp have?


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
  #3  
Old August 29th, 2008, 01:15 PM
Jeff Gaines
Guest
 
Posts: n/a

re: Using 'LIKE' with XML Data


On 29/08/2008 in message <#wPUkxcCJHA.3392@TK2MSFTNGP03.phx.gblMartin
Honnen wrote:
Quote:
>I don't see any XML in your post. Are you sure your question relates to
>XML in the .NET framework? What type does dtTemp have?
It's an XML file I am accessing from a C# class.

The schema from the top of the file is:

<?xml version="1.0" standalone="yes" ?>
- <FileNotesData xmlns="JGFileManager">
- <xs:schema id="FileNotesData" targetNamespace="JGFileManager"
xmlns:mstns="JGFileManager" xmlns="JGFileManager"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
- <xs:element name="FileNotesData" msdata:IsDataSet="true"
msdata:UseCurrentLocale="true">
- <xs:complexType>
- <xs:choice minOccurs="0" maxOccurs="unbounded">
- <xs:element name="tblFileNotes">
- <xs:complexType>
- <xs:sequence>
<xs:element name="RecordNumber" msdata:AutoIncrement="true" type="xs:int" minOccurs="0" />
<xs:element name="LastUpdated" type="xs:string" minOccurs="0" />
<xs:element name="FolderName" type="xs:string" minOccurs="0" />
<xs:element name="FileName" type="xs:string" minOccurs="0" />
<xs:element name="Notes" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

I then use:

DataSet dsTemp = new DataSet();
dsTemp.ReadXml(m_DBPath, XmlReadMode.ReadSchema);
DataTable dtTemp = dsTemp.Tables[m_TableName];

set up the filter here then:

DataRow[] foundRows = dtTemp.Select(filterString);

where the error occurrs.

--
Jeff Gaines Damerham Hampshire UK
"Why is it that when we talk to God we're said to be praying,
but when God talks to us we're schizophrenic?"
  #4  
Old August 29th, 2008, 01:25 PM
Martin Honnen
Guest
 
Posts: n/a

re: Using 'LIKE' with XML Data


Jeff Gaines wrote:
Quote:
DataSet dsTemp = new DataSet();
dsTemp.ReadXml(m_DBPath, XmlReadMode.ReadSchema);
DataTable dtTemp = dsTemp.Tables[m_TableName];
>
set up the filter here then:
>
DataRow[] foundRows = dtTemp.Select(filterString);
>
where the error occurrs.
Try whether it works if you just pass your condition in e.g.
dtTemp.Select("FileName LIKE '%nero%'")


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
  #5  
Old August 29th, 2008, 01:45 PM
Jeff Gaines
Guest
 
Posts: n/a

re: Using 'LIKE' with XML Data


On 29/08/2008 in message <emex6GdCJHA.3268@TK2MSFTNGP03.phx.gblMartin
Honnen wrote:
Quote:
>Jeff Gaines wrote:
>
Quote:
>>DataSet dsTemp = new DataSet();
>>dsTemp.ReadXml(m_DBPath, XmlReadMode.ReadSchema);
>>DataTable dtTemp = dsTemp.Tables[m_TableName];
>>
>>set up the filter here then:
>>
>>DataRow[] foundRows = dtTemp.Select(filterString);
>>
>>where the error occurrs.
>
>Try whether it works if you just pass your condition in e.g.
dtTemp.Select("FileName LIKE '%nero%'")
Thanks Martin :-)

I was trying to be too 'SQL like', in case anybody researches this the
following work:

filterString = string.Format("{0} '%{1}%'", "FileName LIKE ", searchString);
or
filterString = string.Format("{0} '%{1}%'", "Notes LIKE ", searchString);

and even:

filterString = string.Format("{0} '%{1}%'", "FileName LIKE ", searchString);
filterString += " OR ";
filterString += string.Format("{0} '%{1}%'", "Notes LIKE ", searchString);

Thanks again!

--
Jeff Gaines Damerham Hampshire UK
640k ought to be enough for anyone.
(Bill Gates, 1981)
  #6  
Old September 23rd, 2008, 01:25 PM
=?Utf-8?B?QWNodXRoYSBLcmlzaG5hbg==?=
Guest
 
Posts: n/a

re: Using 'LIKE' with XML Data


Excellent Jeff Gaines. Thanks a lot for the solution.
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help: Pre-poulating a web form with xml data captain_gni@yahoo.com answers 1 October 23rd, 2006 01:05 AM
binding webcontrol to a C# method that produces string with xml data jason@cyberpine.com answers 0 September 22nd, 2006 08:55 PM
Experience with XML DataBases Tjerk Wolterink answers 6 December 2nd, 2005 03:35 PM
Client validation not working with XML data islands in tables Dnna answers 2 November 18th, 2005 01:17 AM