473,399 Members | 2,278 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,399 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
2 1077
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
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 #3

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

Similar topics

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, ...
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...
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...
0
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...
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. ...
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: 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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.