473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do i pass params to SQL Templates?

Hi There,

I'm trying to do an XML / XLS transform but am having trouble retrieving my
data. The trouble seems to be with the parameter - if I hard code the id in
the template SQL, everything works, but when I use .CreateParameter to set
the @ID value then i get an exception:

"Microsoft.Data.SqlXml.SqlXmlException: Exception from HRESULT:
0x80040E21. ---> System.Runtime.InteropServices.COMException (0x80040E21):
Exception from HRESULT: 0x80040E21. at
Microsoft.Data.SqlXml.Common.ISQLXMLCommandManaged Interface.ExecuteToOutputS
tream()"

The code looks like this:

Dim oTransform As New Xsl.XslTransform
Dim DataURL As String

Try
'Set response properties
With Response
.ContentType = "text/html"
'Get the data as XML
Dim ID As Integer
ID = Integer.Parse(Request.QueryString("ID"))
Dim oCmd As New SqlXmlCommand(CONN_STRING)
oCmd.CommandType = SqlXmlCommandType.TemplateFile
oCmd.CommandText =
Server.MapPath("./templates/Template.xml")
Dim oParam As SqlXmlParameter = oCmd.CreateParameter()
oParam.Name = "@ID"
oParam.Value = ID

'Transform
oTransform.Load(Server.MapPath("./templates/p7.xsl"))
Dim xDoc As New XPathDocument(oCmd.ExecuteXmlReader,
XmlSpace.Default)

Dim xNav As XPathNavigator = xDoc.CreateNavigator()
oTransform.Transform(xDoc, Nothing, Response.OutputStream,
Nothing)
.Flush()
End With

Catch ex As System.Xml.Xsl.XsltException
Throw New Exception("Doh", ex)
Catch ex As Exception
Throw New Exception("Doh", ex)
Finally
oTransform = Nothing
End Try

And the Template.xml file looks like:

<Plan xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<sql:query>
SELECT Business.*,
FROM Business
WHERE (Business.BusinessID = @ID)
FOR XML AUTO, ELEMENTS
</sql:query>
</Plan>

The only thing the MS documentation has to say is:

"Note If you pass a parameter to a template, the parameter name must begin
with '@' (for example, p.Name="@EmployeeID", where p is a SqlXmlParameter
object)."

which doesn't help much as there isn't an example. (I tried this, but
cannot seem to get it to work)

Any help would be greatly appreciated.

If anyone has successfully passed a parameter to a query like this an
example would be wonderful!

Cheers,

Padgett Rowell
Nov 17 '05 #1
0 1778

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: sklett | last post by:
I have a simple debug and logging class and I would like to be able to send a non-formatted string to my various printing methods, much like string.format(). I have tried to implement this like...
5
by: Julien C. | last post by:
Hi all, I have an "EditeItem.aspx" page which lets me edit properties of an "Item". In the OnClick() event of my Save button, I do save Item changes to the database and then I redirect the user...
2
by: Alex Nitulescu | last post by:
Hi. I have tried to pass two parameters, like this: Response.Redirect(String.Format("NewPage.aspx?Username={0}, Pass={1}", txtUserName.Text, txtPass.Text)) But if I pass Username="Alex" and...
4
by: CsharpGuy | last post by:
I took over an web app (C#) were the developer put everything in a has table then called a method to execute a stored procedure, now I'm running into some issues were if I do an update and a NULL...
7
by: Jess | last post by:
Hello, I learned that when I work with templates in C++, I should have functions that pass arguments by reference because the type of object is not known. Does it mean that if I have a function...
5
by: Larry Bud | last post by:
I'm writing a class to create a specifically formatted fixed width file. It's 800 characters wide, consisting of approx 30 fields. So I need to pass 30 variables, maybe 10 are required. Should...
5
by: JohnDriver | last post by:
Hi, I am having a form which has a text box and 3 radio buttons. I am using GET method in Ajax to pass the value. I can pass the value of the textbox fine but how to pass the value of radio...
3
by: MimiMi | last post by:
How do I get the pass by reference-thing to work in this example? Since I'm still new to C I sometimes get confused in this matter, and this is one of those occasions. I'm obviously doing...
6
by: (2b|!2b)==? | last post by:
I am expecting a string of this format: "id1:param1,param2;id2:param1,param2,param3;id" The tokens are seperated by semicolon ";" However each token is really a struct of the following...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.