Connecting Tech Pros Worldwide Help | Site Map

Using 'LIKE' with XML Data

 
LinkBack Thread Tools Search this Thread
  #1  
Old August 29th, 2008, 11:35 AM
Jeff Gaines
Guest
 
Posts: n/a
Default Using 'LIKE' with XML Data


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, 11:55 AM
Martin Honnen
Guest
 
Posts: n/a
Default 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, 12:15 PM
Jeff Gaines
Guest
 
Posts: n/a
Default 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, 12:25 PM
Martin Honnen
Guest
 
Posts: n/a
Default 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, 12:45 PM
Jeff Gaines
Guest
 
Posts: n/a
Default 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, 12:25 PM
=?Utf-8?B?QWNodXRoYSBLcmlzaG5hbg==?=
Guest
 
Posts: n/a
Default Re: Using 'LIKE' with XML Data

Excellent Jeff Gaines. Thanks a lot for the solution.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.