473,385 Members | 1,727 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,385 software developers and data experts.

SqlDataAdapter Parameterized Query - Apostrophe Issue

I have searched and can't find any articles pertaining to this issue...

I am filling a dataset using a SqlDataAdapter that was instantiated
with a SqlCommand object. When the Fill method is called, I get the
"incorrect syntax near..." error message that you typically see when a
query is constructed and apostrophes aren't doubled up.

However, it was my understanding that using the SqlCommand object and
creating/populating my parameters here should help avoid the apostrophe
issue. Here's a bit o' code...

Dim MyParamValue As String = "Bob's Gym" 'APOSTROPHE IN PARAM

Dim command As New SqlClient.SqlCommand
With command
.CommandText = "my_sproc"
.CommandType = CommandType.StoredProcedure
.Parameters.Add(New SqlClient.SqlParameter("@myParameter",
MyParamValue))
.Connection = New
SqlClient.SqlConnection("server=myserver;database= mydbs;uid=myuid;pwd=mypwd")
End With
Dim adapt As New SqlClient.SqlDataAdapter(command)
Dim ds As New DataSet
adapt.Fill(ds)

The "incorrect syntax near..." error is thrown on Fill. If I
explicitly double up all occurrences of apostrophes in my parameter
values before execution, it runs fine.

Is this a known thing? Am I missing something obvious?

Thanks guys and gals,

Ryan

Mar 27 '06 #1
2 2765

herlihyboy wrote:
I have searched and can't find any articles pertaining to this issue...

I am filling a dataset using a SqlDataAdapter that was instantiated
with a SqlCommand object. When the Fill method is called, I get the
"incorrect syntax near..." error message that you typically see when a
query is constructed and apostrophes aren't doubled up.


Is there any dynamic SQL in the sproc?

--
Larry Lard
Replies to group please

Mar 28 '06 #2

Larry Lard wrote:
herlihyboy wrote:
I have searched and can't find any articles pertaining to this issue...

I am filling a dataset using a SqlDataAdapter that was instantiated
with a SqlCommand object. When the Fill method is called, I get the
"incorrect syntax near..." error message that you typically see when a
query is constructed and apostrophes aren't doubled up.


Is there any dynamic SQL in the sproc?


Good call, Larry. Thanks a bunch.

Ryan

Mar 28 '06 #3

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

Similar topics

1
by: gary b | last post by:
Hello When I use a PreparedStatement (in jdbc) with the following query: SELECT store_groups_id FROM store_groups WHERE store_groups_id IS NOT NULL AND type = ? ORDER BY group_name
8
by: deko | last post by:
I'm trying to open a Recordset based on a parameterized query. I'm kind of new to parameterized queries, so I'm sure I'm missing something simple. Set qdfs = db.QueryDefs Set qdf =...
2
by: deko | last post by:
Is it possible to build a parameterized query from another parameterized query? I've tried two variations of this and can't seem to get it to work (using DAO). Any suggestions welcome! I...
11
by: Trevor | last post by:
Hi, I currently have the following code in a subform. If Not rstPDAddresses.EOF And Not rstPDAddresses.BOF Then With rstPDAddresses txtautoAddressID.ControlSource = "='" & Nz(!autoAddressID,...
4
by: Michael Jones | last post by:
Ok.......... I'm trying to fill a parameterized table onto a Dataset via a sqlDataAdapter. It works fine if I fill the Dataset with all the column fields. What I want to do though is to only fill...
11
by: anony | last post by:
Hello, I can't figure out why my parameterized query from an ASP.NET page is dropping "special" characters such as accented quotes & apostrophes, the registered trademark symbol, etc. These...
2
by: JSheble | last post by:
After building a parameterized ADO query, is there a method or a statement where you could see the actual query, with the parameterized values included?? -- Using Opera's revolutionary e-mail...
6
by: Alan T | last post by:
I want to get records by joining 2 tables: SqlDataAdapter da = new SqlDataAdapter ("select p.ID, p.Name, c.Name from Product p left join Category c on p.catID = c.ID"); DataSet ds = new...
8
by: Roland Hall | last post by:
In Access you use "*" + + "*", + can be replaced with & Calling a parameterized query in Access requires % be used in place of *, however, all that I have read show dynamic SQL passed to Access: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.