473,396 Members | 1,843 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.

Question with paramater passed to sp

Hi
I have a problem populating my datagrid when the values passed have an apostrophie (') like this test's. Any other values work. This is my asp.net cod

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
'Put user code to initialize the page her
Dim s As String = Request.QueryString("id").ToString(
If Not Page.IsPostBack The

Dim conPos As SqlConnectio
Dim cmdSel As SqlDataAdapte
Dim ds As DataSe

conPos = New SqlConnection("Server = prod01\enterprise;UID=sa;PWD=xxxx;Database=POS"
cmdSel = New SqlDataAdapter("LoadOrderRegulation", conPos

cmdSel.SelectCommand.CommandType = CommandType.StoredProcedur

cmdSel.SelectCommand.Parameters.Add(New SqlParameter("@productName", SqlDbType.VarChar, 15)
cmdSel.SelectCommand.Parameters("@productName").Va lue =
ds = New DataSe
cmdSel.Fill(ds, "Oreg"

DataGrid1.DataSource = ds.Tables("Oreg").DefaultVie
DataGrid1.DataBind(
End I

End Su
This is my stored pro

create procedure LoadOrderRegulation
@productName varchar(50
a

declare @productNumber varchar(10

exec POS_GetProductNumber @productName, @productNumber OUTPU

If len(@productNumber) = 1

Set @productNumber = '0000' + @productNumbe

If len(@productNumber) =

Set @productNumber = '000' + @productNumbe

If len(@productNumber) =

Set @productNumber = '00' + @productNumbe

If len(@productNumber) =

Set @productNumber = '0' + @productNumbe
select
POS_Product_Number
POS_Store_Number
POS_Account_Number
POS_Current_Draw
POS_Proposed_Draw
POS_Average_Sale
POS_Date_Regulated
POS_Adjustmen

from pos_order_regulation where POS_Product_Number = @productNumbe
retur

I think my stored proc is expecting test''s instead of test's. How can I handle this. If I execute the stored procedure from query analyzer like this

declare @datatest varchar(20

exec LoadOrderRegulation 'test''s', @datatest OUTPU

Select @datatest

it work

Nov 18 '05 #1
1 920
Here's how I solve a similar problem, building a SQL query with
Stringbuilder (yes, soon to be a stored procedure...):

sbldr.Append(Me.shipTo_First_Name.Replace("'", "''")) : sbldr.Append("','")

"Chris" <an*******@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
Hi,
I have a problem populating my datagrid when the values passed have an apostrophie (') like this test's. Any other values work. This is my asp.net
code
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here

Dim s As String = Request.QueryString("id").ToString()
If Not Page.IsPostBack Then
Dim conPos As SqlConnection
Dim cmdSel As SqlDataAdapter
Dim ds As DataSet

conPos = New SqlConnection("Server = prod01\enterprise;UID=sa;PWD=xxxx;Database=POS")
cmdSel = New SqlDataAdapter("LoadOrderRegulation", conPos)

cmdSel.SelectCommand.CommandType = CommandType.StoredProcedure

cmdSel.SelectCommand.Parameters.Add(New SqlParameter("@productName", SqlDbType.VarChar, 15)) cmdSel.SelectCommand.Parameters("@productName").Va lue = s

ds = New DataSet
cmdSel.Fill(ds, "Oreg")

DataGrid1.DataSource = ds.Tables("Oreg").DefaultView
DataGrid1.DataBind()


End If

End Sub

This is my stored proc


create procedure LoadOrderRegulation(
@productName varchar(50)
)

as

declare @productNumber varchar(10)
exec POS_GetProductNumber @productName, @productNumber OUTPUT

If len(@productNumber) = 1

Set @productNumber = '0000' + @productNumber

If len(@productNumber) = 2
Set @productNumber = '000' + @productNumber

If len(@productNumber) = 3
Set @productNumber = '00' + @productNumber

If len(@productNumber) = 4
Set @productNumber = '0' + @productNumber


select
POS_Product_Number,
POS_Store_Number,
POS_Account_Number,
POS_Current_Draw,
POS_Proposed_Draw,
POS_Average_Sale,
POS_Date_Regulated,
POS_Adjustment

from pos_order_regulation where POS_Product_Number = @productNumber

return
I think my stored proc is expecting test''s instead of test's. How can I handle this. If I execute the stored procedure from query analyzer like this

declare @datatest varchar(20)

exec LoadOrderRegulation 'test''s', @datatest OUTPUT

Select @datatest

it works

Nov 18 '05 #2

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

Similar topics

6
by: WertmanTheMad | last post by:
Ok, This sounds dangerous (and yes I know it is) But its in a controlled enviroment and I really need to know how to do this. How can I pass a Subquery for an Exist or In clause as a...
4
by: WertmanTheMad | last post by:
Ok here goes, another odd SQL Question ....as always.. How do I get ... The value of a paramater passed to say a Trigger OR The SQL Itself Like this , say I have a Trigger set on delete, ...
2
by: Andre | last post by:
I'm trying to write a Password generating program which will fill one of the fields in our Accounts Table with an eight-digit password made up of numerals, upper and lower case letters. I'm...
2
by: Max Adams | last post by:
Question about using delegates with a string paramater to return a ListViewItem object... All, I have a thread and I want this thread to post messages to the main GUI thread using a delegate....
1
by: Chris | last post by:
Hi I have a problem populating my datagrid when the values passed have an apostrophie (') like this test's. Any other values work. This is my asp.net cod Private Sub Page_Load(ByVal sender As...
5
by: gane kol | last post by:
Hi I have a set of Yes/No radio buttons with textboxes for each. I need to write a common customvalidation function that checks, if radiobutton "yes" is selected, the value in the corresponding...
0
by: Ihsan_al-shorafa | last post by:
We are trying to put together an exception handling framework and were wondering if you can help us out with a problem that we ran into... Q: Is there a way, through reflection or any other...
2
by: Jim Langston | last post by:
In my function/method paramater list I try to keep constant correctness. I.E. I would use: int Foo( const char* a, int b ) instead of int Foo( char* a, int b ) My question reguards int b. ...
7
by: Cirene | last post by:
I have a stored procedure named insertcompany. I keep getting the error: Sys.webforms.pagerequestmanagerservererrorexception: Procedure or function 'InsertCompany' expects parameter...
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.