.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Problems escaping apostrophe when using an XPath query with SelectSingleNode

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :ASP.Net
I have an XML node which I am trying to search for a specific node which has a given value, but I am having problems when the value contains an apostrophe. I have tried replacing the apostrophe with &apos as follows:                string encodedTitle = title.Replace("'", "'");                 string XmlPath = String.Format("item[title = \'{0}\']", encodedTitle);                 return NodeChannel.SelectSingleNode(XmlPath);                string encodedSearchString = searchString.Replace("'", "'");                string XmlPath = String.Format("item[title = \'{0}\']", encodedSearchString);                return myNode.SelectSingleNode(XmlPath);However, this does not seem to find search strings with an apostrophe (it doesn't throw an exception or anything, it just returns null). Search strings without an apostrophe work fine. Is there any way I can fix this?

View Complete Post

More Related Resource Links

Sub Query Problems

Apologies if I have not posted this in the correct section.  I am having some difficulties with some sub queries. First I'd like to show the database design. Rez_Desc Table Rez_ID Rez_Number Client_Name Arriving_ID Pickup_ID 1001 201000123 Mr. Ross 1 2 1002 201000124 Mrs. Smith 2 1 Arrival_Desc Table Arriving_ID Label 1 AUS 2 USA OffSite_Desc Table OffSite_ID Label 1 AUS 2 USA Ok so this is my table structure, simplified. This is the query I am trying to run. SELECT Rez_Desc.Rez_Number AS RezNum, (SELECT OD.Label FROM Offsite_Desc OD LEFT JOIN Rez_Desc AS RD ON OD.Offsite_ID = RD.Pickup_ID AND RD.Rez_ID=Rez_Desc.Rez_ID) AS Pickup, (SELECT AR.Label FROM Arrival_Desc AR LEFT JOIN Rez_Desc AS RD ON AR.Arriving_ID = RD.Arriving_ID AND RD.Rez_ID=Rez_Desc.Rez_ID) AS DropOff FROM Rez_Desc And I get the following error:- Msg 512, Level 16, State 1, Line 1 Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. To my knowledge and understanding it is being caused because the sub query is returning more than 1 result which it should not be doing.  Seeing as how in my example table above I have 2 entries, both with relevant ID's etc. Need some help!

Problems writing a dynamic L2E query

I'm trying to re-work a L2E query to be more dynamic, but I'm not having much luck. Basically, I have two parameters (and many more to come, just laying the foundation), and the parameters are both optional from a user-endpoint.Originally I wrote this static expression:int personnelId = 1234; int divisionId = 1234; var results = (from a in ctx.Attendees from d in a.Divisions join p in ctx.Personnel on a.PersonnelID equals p.PersonnelID where a.PersonnelID == personnelId && d.DivisionID == divisionId select new Attendee { firstName = a.FirstName, lastName = a.LastName });Attendee is a POCO. After I wrote this, I realized that if personnelId or divisionId weren't passed in (or if just one were passed in) I'd want a different result set. I'm conceptualizing the idea like this (doesn't compile, but you get the drift):var results = (from a in ctx.Attendees select new Attendee { firstName = p.FirstName, lastName = p.LastName }); if (personnelId != null) { results = (from a in results join p in ctx.Personnel on a.PersonnelID equals p.PersonnelID where a.PersonnelID == personnelId select a); } if (divisionId != null) { results = (from a in results from d in a.Divisions where d.DivisionID == divisionId select a); } results = results.ToList();Doesn't work well though, because my

XPath Query in Where clause of SQL query

Hi, I have one table where one column contains XML format data inside and i have more than one row in my table.  i.e. <test><id>1</id></test> . . . . . <test><id>N</id></test> Here  the XML id could be upto N as shown above. Now i want to query on my table and in Where clause i want to put XPath Query on this column so that i could put a condition on specific ID and based on that iD i could get the whole data row from table, i am thinking query should be as below Select * from XYZ where col1.query('//test/id') >= 5 or Select * from XYZ where col1.value('(/test/id)[1]', 'int')>= 5 Here the first query where i am using col1.query('//test/id') >= 5, There is syntax error, and in second one, first of all.. i have to declare the XML type local variable then set that vaiable like  SET @localvariable = col1 from XYZ and then @localvariable.value('(/test/id)[1]', 'int'), eventhough i cannot put the range (>=,<=) here, as well as we cannot get the all rows in @localvariable when we set the value to the local variable. but i want my query should be as i show above. How can i do this ? Any suggestion.....  --Jai JP Sharma

Binding a Button's Content property to an XPath query, Accelerator functionality is lost



I'm using WPF 3.5.

I'm binding a button's Content property to an XPath query, and all is well until I try to make use of the Accelerator feature. 

When I hardcode the text, and place an _ (underscore) in the content, it renders as an accelerator key when the Alt key is pressed.  However, when the content is a binding expression that uses an XPath query, the underscore does not render as an accelerator key.  It simply appears as part of the content. 

Here is some simplified XAML code to illustrate:

<UserControl x:Class="Myapp.UI.Screens.PortalScreens.Portal"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
		<XmlDataProvider x:Key="languageResources" d:IsDataSource="True" Source="Resources\Language\English.xml" />
<Grid x:Name="layoutRoot">
		<Button x:Name="ExitButtonWithHardCodedText" Grid.Row=&quo

problems in pivot query




             I am using following pivot query  but not getting result as single row getting as 4 rows.

One more problem i am unable to pass dates as parameters to storeprocedure something like this

select [@date] .

        SELECT 'Forecasted' AS HeadCount,
[8/1/2010], [8/8/2010], [8/15/2010], [8/22/2010]
FROM TblEmpCount) AS SourceTable
FOR StartDate IN ([8/1/2010], [8/8/2010], [8/15/2010], [8/22/2010])
) AS PivotTable;

I am getting result as 4 rows but i want result in single row like this

HeadCount    8/1/2010     8/8/2010    8/15/2010    8/222/2010

Forecasted     191                182                 176                169





database query problems


Hello All, I have a result table in MS SQL Database server (2005).

Subject   Exam                 SubExam   Year     Marks

Math       First Terminal    CT              2010    18
Math       First Terminal    Hall Exam   2010    67.2

Science   First Terminal    CT              2010    20
Science   First Terminal    Hall Exam   2010    78

Now how can I get the result followningly

                                First Terminal

                        CT       Hall Exam      Total


query problems


Hello All, I have a result table in MS SQL Database server (2005).

Subject   Exam                 SubExam   Year     subjective objective practical

Math       First Terminal    CT              2010    18             0              0
Math       First Terminal    Hall Exam   2010    38             46            0

Science   First Terminal    CT              2010    20             0              0
Science   First Terminal    Hall Exam   2010    32            40      &

SELECT and UPDATE query problems



I have a web form that should display advertisements depending of the number of impressions (number stored in a database) and I also need to update the number of impressions when page is loaded. The advertisements are displayed on a web page, but the problem is I don't know where to insert the SqlCommand for updating number of impressions.

Labels are used for displaying the number of impressions.  

        String connectionString = WebConfigurationManager.ConnectionStrings["CMS"].ToString();
        using (SqlConnection connection = new SqlConnection(connectionString))

            using (SqlCommand commandReklama = new SqlCommand("SELECT * FROM Reklama", connection))
                SqlDataReader readerReklama = commandReklama.ExecuteReader();
                while (readerReklama.Read())
                    string redirectUrl = readerReklama.GetString(1);
                    string url = readerReklama.GetString(2);
                    int brojPrikazivanja = readerReklama.GetInt32(3);
                    bool show = readerReklama.GetBoolean(4);                  
                    string naziv = readerReklama.GetString(5);
                    int location = readerReklama.GetInt32(6);

                    if (

Xpath query to find an Node who's attribute contains a forward slash - Going crazy


If  I have a .XML file that contains the following example:

<Socks Style ="Business/Business Casual/Casual"


When I try to use the Xpath expression below to find the element above by searching for the value contained in the Style Attribute, the expression returns null:

//Socks [@Style='Business/Business Casual/Casual'] 

I downloaded xPath virtualizer and I noticed that the expression above is adding the namespace alias when it finds the embedded forward slash contained in the value of the Style Attribute (which is of course not what I want to happen).  This is driving me up a tree!!  Isn't there a way to escape the forward slash?  I know it is the slash that is the problem because for testing purposes I substituted dashes (-) in one of the nodes' Style Attribute values and then changed the xpath expression to match and it returned the exact node.

My goal is to do some replacements on all elements with the Style attribute based on each contents but I can't even try that because of this roadblock.

Please help anyone



Problems with AND/OR in SQL query in strongly type datasets



In my ASP.NET web application I am using strongly typed datasets for data access. In my dataset.xsd class I have added an SQL query that works in SQL Management Studio, and when executed in the Table Adapter Query Configuration Wizard --> Execute Query form. But when invoked from the application using the autogenerated table adapter it returns no hits.

INNER JOIN Department ON Department.Dep_Id = Device.Dev_Dep_id 
INNER JOIN Customer ON Customer.Cus_Id = Department.Dep_CustomerNr 
INNER JOIN RootCustomer ON RootCustomer.RCus_Id = Customer.RCus_Id
(RootCustomer.RCus_Id = @CustomerId) AND (Device.Dev_Status = 10) AND (Device.Dev_serial LIKE '%' + @searchPattern + '%') OR
(RootCustomer.RCus_Id = @CustomerId) AND (Device.Dev_Status = 10) AND (Device.Dev_CustMark LIKE '%' + @searchPattern + '%') OR
(RootCustomer.RCus_Id = @CustomerId) AND (Device.Dev_Status = 10) AND (Device.Dev_IpAddress LIKE '%' + @searchPattern + '%') OR
(RootCustomer.RCus_Id = @CustomerId) AND (Device.Dev_Status = 10) AND (Device.Dev_ArticleNr LIKE '%' + @searchPattern + '%') OR
(RootCustomer.RCus_Id = @CustomerId) AND (Device.Dev_Status = 10) AND (Device.Dev_Descr LIKE '%' + @searchPattern + '%')
ORDER BY Device.Dev_serial

What possib

XPATH query for date range



I am pulling the data into a column as XML data type and I want to query within the below XML that is returned.

I want to construct XPATH that allows me to search for a date range where Field Name = Review Date. I want records to be returned whenever the Review Date falls within a date range that I am passing from the UI

<tr2 fieldcode="23" fieldvalue="Periodic Review">

  <LF FieldName="Request Type" />


<tr2 fieldcode="26" fieldvalue="05/04/2010">

  <LF FieldName="Review Date" />


<tr2 fieldcode="27">

  <LF FieldName="Total Number of Accounts" />


<tr2 fieldcode="28">

  <LF FieldName="Total Number of Roles" />


<tr2 fieldcode="27" fieldvalue="28">

  <LF FieldName="Total Number of Accounts" />


<tr2 fieldcode="28" fieldvalue="252">

  <LF FieldName="Total Number of Roles" />


Sub query and problems

SELECT FirstName, LastName, EmployeeNumber, SSN, SUM(Credits)
FROM Employees E 

MS SQL Server: Search All Tables, Columns & Rows For Data or Keyword Query

If you need to search your entire database for specific data, this query will come in handy.

So when a client needs a custom report or some sort of custom development using Great Plains, most of the time I will have to track down the data in the system by running this query and find the table(s) it is in.

Top .NET Performance Problems and how to avoid them

Every time I work with one of our .NET customers to help them with managing their application performance I come across the same problems as seen with other clients before: lots of ADO.NET queries, many hidden exceptions in core or 3rd party .NET libraries, slow 3rd party components, inefficient custom code

How to Encrypt Query String Parameters in ASP.NET

Encrypt Query String Parameters in ASP.NET.u can send secure data one page another page u can also use query string to encrypt

Content Query Web Part missing in SharePoint 2010

If you don't see content query web part listed in the web parts list, this is because you have not enabled "Search Server Web Parts" feature in site collection features. Enable this feature and content query web part will show in the list of web parts.

Visual Studio 2008 Memory problems


My memory in task manager reaches about 900,000K  and I don't know why it does this. Definately slows everything down, especially when I rebuild my tableAdapters, takes about 30 seconds sometimes to rebuild the project.

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend