Need help setting up cast...
Need help setting up cast...
am 07.04.2008 16:47:29 von JJ297
Here's my stored procedure:
Create procedure Test
@Button varchar(30),
@mod char (10),
@FromDate datetime,
@ToDate datetime
AS
if @button='Button10'
begin
select * from spslist
where mod=@mod and pmtdate between @fromdate and @ToDate and PMTAMT <=
53000.01
order by pmtamt
end
if @button='Button20'
begin
select * from spslist
where mod=@mod and pmtdate between @fromdate and @ToDate and pmtamt
between 49999.99 and 53000.01
order by pmtamt
end
Here's the code behind page. How do I cast @button? Tried this below
but it's not working.
Dim conn As New
Data.SqlClient.SqlConnection(ConfigurationManager.Connection Strings("SPSConnectionString").ConnectionString)
Dim cmd As New Data.SqlClient.SqlCommand
Dim cmdSampling As New Data.SqlClient.SqlCommand
With cmdSampling
.CommandType = Data.CommandType.StoredProcedure
.CommandText = "Test"
.Connection = conn
.Parameters.AddWithValue("@mod",
DropDownList1.SelectedValue)
.Parameters.AddWithValue("@Button", CType(@button,
varchar(30))
.Parameters.AddWithValue("@FromDate", FromDte.Text)
.Parameters.AddWithValue("@ToDate", ToDTE.Text)
End With
Re: Need help setting up cast...
am 07.04.2008 17:12:17 von Courtney
"JJ297" wrote in message
news:29780d77-4255-4a56-a20b-a0eea00aaff6@59g2000hsb.googleg roups.com...
> Here's my stored procedure:
>
> Create procedure Test
>
> @Button varchar(30),
> @mod char (10),
> @FromDate datetime,
> @ToDate datetime
>
>
> AS
> if @button='Button10'
> begin
> select * from spslist
> where mod=@mod and pmtdate between @fromdate and @ToDate and PMTAMT <=
> 53000.01
> order by pmtamt
> end
>
> if @button='Button20'
> begin
> select * from spslist
> where mod=@mod and pmtdate between @fromdate and @ToDate and pmtamt
> between 49999.99 and 53000.01
> order by pmtamt
> end
>
> Here's the code behind page. How do I cast @button? Tried this below
> but it's not working.
>
> Dim conn As New
> Data.SqlClient.SqlConnection(ConfigurationManager.Connection Strings("SPSConnectionString").ConnectionString)
>
> Dim cmd As New Data.SqlClient.SqlCommand
> Dim cmdSampling As New Data.SqlClient.SqlCommand
>
> With cmdSampling
> .CommandType = Data.CommandType.StoredProcedure
>
> .CommandText = "Test"
> .Connection = conn
>
> .Parameters.AddWithValue("@mod",
> DropDownList1.SelectedValue)
> .Parameters.AddWithValue("@Button", CType(@button,
> varchar(30))
> .Parameters.AddWithValue("@FromDate", FromDte.Text)
> .Parameters.AddWithValue("@ToDate", ToDTE.Text)
>
> End With
Since the type of parameter is varchar the value passed should be a string.
Your code does not indicate where you get the value from. If you are
checking to see if a particular button was pressed then in the button
clicked event get the name of the button from code and pass that as value.
Hope this helps
Lloyd Sheen
Re: Need help setting up cast...
am 07.04.2008 17:35:58 von JJ297
On Apr 7, 11:12=A0am, "Lloyd Sheen" wrote:
> "JJ297" wrote in message
>
> news:29780d77-4255-4a56-a20b-a0eea00aaff6@59g2000hsb.googleg roups.com...
>
>
>
>
>
> > Here's my stored procedure:
>
> > Create procedure Test
>
> > @Button varchar(30),
> > @mod char (10),
> > @FromDate datetime,
> > @ToDate datetime
>
> > AS
> > if @button=3D'Button10'
> > begin
> > select * from spslist
> > where mod=3D@mod and pmtdate between @fromdate and @ToDate and PMTAMT <=
=3D
> > 53000.01
> > order by pmtamt
> > end
>
> > if @button=3D'Button20'
> > begin
> > select * from spslist
> > where mod=3D@mod and pmtdate between @fromdate and @ToDate and pmtamt
> > between 49999.99 and 53000.01
> > order by pmtamt
> > end
>
> > Here's the code behind page. =A0How do I cast @button? Tried this below
> > but it's not working.
>
> > Dim conn As New
> > Data.SqlClient.SqlConnection(ConfigurationManager.Connection Strings("SPS=
Con=ADnectionString").ConnectionString)
>
> > =A0 =A0 =A0 =A0Dim cmd As New Data.SqlClient.SqlCommand
> > =A0 =A0 =A0 =A0Dim cmdSampling As New Data.SqlClient.SqlCommand
>
> > =A0 =A0 =A0 =A0With cmdSampling
> > =A0 =A0 =A0 =A0 =A0 =A0.CommandType =3D Data.CommandType.StoredProcedure=
>
> > =A0 =A0 =A0 =A0 =A0 =A0.CommandText =3D "Test"
> > =A0 =A0 =A0 =A0 =A0 =A0.Connection =3D conn
>
> > =A0 =A0 =A0 =A0 =A0 =A0.Parameters.AddWithValue("@mod",
> > DropDownList1.SelectedValue)
> > =A0 =A0 =A0 =A0 =A0 =A0.Parameters.AddWithValue("@Button", CType(@button=
,
> > varchar(30))
> > =A0 =A0 =A0 =A0 =A0 =A0.Parameters.AddWithValue("@FromDate", FromDte.Tex=
t)
> > =A0 =A0 =A0 =A0 =A0 =A0.Parameters.AddWithValue("@ToDate", ToDTE.Text)
>
> > =A0 =A0 =A0 =A0End With
>
> Since the type of parameter is varchar the value passed should be a string=
..
> Your code does not indicate where you get the value from. =A0If you are
> checking to see if a particular button was pressed then in the button
> clicked event get the name of the button from code and pass that as value.=
>
> Hope this helps
> Lloyd Sheen- Hide quoted text -
>
> - Show quoted text -
Yes I want to see which button is clicked, Sorry I left out some of
the code.
Tried this but it's still not working
.Parameters.AddWithValue("@Button" Button10)
Code below
Protected Sub Button10_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button10.Click
Session("Mod") =3D DropDownList1.SelectedValue
Session("Fromdate") =3D FromDte.Text 'used to grab info from the
two text boxes on the aspx page
Session("toDate") =3D ToDTE.Text
Dim conn As New
Data.SqlClient.SqlConnection(ConfigurationManager.Connection Strings("SPSConn=
ectionString").ConnectionString)
Dim cmd As New Data.SqlClient.SqlCommand
Dim cmdSampling As New Data.SqlClient.SqlCommand
With cmdSampling
.CommandType =3D Data.CommandType.StoredProcedure
.CommandText =3D "GetSampling"
.Connection =3D conn
.Parameters.AddWithValue("@mod",
DropDownList1.SelectedValue)
.Parameters.AddWithValue("@Button" Button10)
.Parameters.AddWithValue("@FromDate", FromDte.Text)
.Parameters.AddWithValue("@ToDate", ToDTE.Text)
Response.Redirect("SamplingReport.aspx")
End With
End Sub
Re: Need help setting up cast...
am 07.04.2008 18:24:17 von Courtney
"JJ297" wrote in message
news:c5e98cb3-6201-4675-ba7f-7e0af57ab999@e39g2000hsf.google groups.com...
On Apr 7, 11:12 am, "Lloyd Sheen" wrote:
> "JJ297" wrote in message
>
> news:29780d77-4255-4a56-a20b-a0eea00aaff6@59g2000hsb.googleg roups.com...
>
>
>
>
>
> > Here's my stored procedure:
>
> > Create procedure Test
>
> > @Button varchar(30),
> > @mod char (10),
> > @FromDate datetime,
> > @ToDate datetime
>
> > AS
> > if @button='Button10'
> > begin
> > select * from spslist
> > where mod=@mod and pmtdate between @fromdate and @ToDate and PMTAMT <=
> > 53000.01
> > order by pmtamt
> > end
>
> > if @button='Button20'
> > begin
> > select * from spslist
> > where mod=@mod and pmtdate between @fromdate and @ToDate and pmtamt
> > between 49999.99 and 53000.01
> > order by pmtamt
> > end
>
> > Here's the code behind page. How do I cast @button? Tried this below
> > but it's not working.
>
> > Dim conn As New
> > Data.SqlClient.SqlConnection(ConfigurationManager.Connection Strings("SPSConnectionString").ConnectionString)
>
> > Dim cmd As New Data.SqlClient.SqlCommand
> > Dim cmdSampling As New Data.SqlClient.SqlCommand
>
> > With cmdSampling
> > .CommandType = Data.CommandType.StoredProcedure
>
> > .CommandText = "Test"
> > .Connection = conn
>
> > .Parameters.AddWithValue("@mod",
> > DropDownList1.SelectedValue)
> > .Parameters.AddWithValue("@Button", CType(@button,
> > varchar(30))
> > .Parameters.AddWithValue("@FromDate", FromDte.Text)
> > .Parameters.AddWithValue("@ToDate", ToDTE.Text)
>
> > End With
>
> Since the type of parameter is varchar the value passed should be a
> string.
> Your code does not indicate where you get the value from. If you are
> checking to see if a particular button was pressed then in the button
> clicked event get the name of the button from code and pass that as value.
>
> Hope this helps
> Lloyd Sheen- Hide quoted text -
>
> - Show quoted text -
Yes I want to see which button is clicked, Sorry I left out some of
the code.
Tried this but it's still not working
.Parameters.AddWithValue("@Button" Button10)
Code below
Protected Sub Button10_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button10.Click
Session("Mod") = DropDownList1.SelectedValue
Session("Fromdate") = FromDte.Text 'used to grab info from the
two text boxes on the aspx page
Session("toDate") = ToDTE.Text
Dim conn As New
Data.SqlClient.SqlConnection(ConfigurationManager.Connection Strings("SPSConnectionString").ConnectionString)
Dim cmd As New Data.SqlClient.SqlCommand
Dim cmdSampling As New Data.SqlClient.SqlCommand
With cmdSampling
.CommandType = Data.CommandType.StoredProcedure
.CommandText = "GetSampling"
.Connection = conn
.Parameters.AddWithValue("@mod",
DropDownList1.SelectedValue)
.Parameters.AddWithValue("@Button" Button10)
.Parameters.AddWithValue("@FromDate", FromDte.Text)
.Parameters.AddWithValue("@ToDate", ToDTE.Text)
Response.Redirect("SamplingReport.aspx")
End With
End Sub
You are trying to use the Button rather than either the Button.text or
Button.clientid.
You should turn option strict and option explicit on. If you do then you
will get much more meaningful error messages before you attempt to test.
Hope this helps
LLoyd Sheen
Re: Need help setting up cast...
am 07.04.2008 20:44:13 von JJ297
On Apr 7, 12:24=A0pm, "Lloyd Sheen" wrote:
> "JJ297" wrote in message
>
> news:c5e98cb3-6201-4675-ba7f-7e0af57ab999@e39g2000hsf.google groups.com...
> On Apr 7, 11:12 am, "Lloyd Sheen" wrote:
>
>
>
>
>
> > "JJ297" wrote in message
>
> >news:29780d77-4255-4a56-a20b-a0eea00aaff6@59g2000hsb.google groups.com...
>
> > > Here's my stored procedure:
>
> > > Create procedure Test
>
> > > @Button varchar(30),
> > > @mod char (10),
> > > @FromDate datetime,
> > > @ToDate datetime
>
> > > AS
> > > if @button=3D'Button10'
> > > begin
> > > select * from spslist
> > > where mod=3D@mod and pmtdate between @fromdate and @ToDate and PMTAMT =
<=3D
> > > 53000.01
> > > order by pmtamt
> > > end
>
> > > if @button=3D'Button20'
> > > begin
> > > select * from spslist
> > > where mod=3D@mod and pmtdate between @fromdate and @ToDate and pmtamt
> > > between 49999.99 and 53000.01
> > > order by pmtamt
> > > end
>
> > > Here's the code behind page. How do I cast @button? Tried this below
> > > but it's not working.
>
> > > Dim conn As New
> > > Data.SqlClient.SqlConnection(ConfigurationManager.Connection Strings("S=
PSConnectionString").ConnectionString)
>
> > > Dim cmd As New Data.SqlClient.SqlCommand
> > > Dim cmdSampling As New Data.SqlClient.SqlCommand
>
> > > With cmdSampling
> > > .CommandType =3D Data.CommandType.StoredProcedure
>
> > > .CommandText =3D "Test"
> > > .Connection =3D conn
>
> > > .Parameters.AddWithValue("@mod",
> > > DropDownList1.SelectedValue)
> > > .Parameters.AddWithValue("@Button", CType(@button,
> > > varchar(30))
> > > .Parameters.AddWithValue("@FromDate", FromDte.Text)
> > > .Parameters.AddWithValue("@ToDate", ToDTE.Text)
>
> > > End With
>
> > Since the type of parameter is varchar the value passed should be a
> > string.
> > Your code does not indicate where you get the value from. If you are
> > checking to see if a particular button was pressed then in the button
> > clicked event get the name of the button from code and pass that as valu=
e.
>
> > Hope this helps
> > Lloyd Sheen- Hide quoted text -
>
> > - Show quoted text -
>
> Yes I want to see which button is clicked, Sorry I left out some of
> the code.
>
> Tried this but it's still not working
>
> =A0 .Parameters.AddWithValue("@Button" Button10)
>
> Code below
>
> =A0Protected Sub Button10_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button10.Click
> =A0 =A0 =A0 =A0 Session("Mod") =3D DropDownList1.SelectedValue
> =A0 =A0 =A0 =A0 Session("Fromdate") =3D FromDte.Text 'used to grab info fr=
om the
> two text boxes on the aspx page
> =A0 =A0 =A0 =A0 Session("toDate") =3D ToDTE.Text
>
> =A0 =A0 =A0 =A0 Dim conn As New
> Data.SqlClient.SqlConnection(ConfigurationManager.Connection Strings("SPSCo=
n=ADnectionString").ConnectionString)
>
> =A0 =A0 =A0 =A0 Dim cmd As New Data.SqlClient.SqlCommand
> =A0 =A0 =A0 =A0 Dim cmdSampling As New Data.SqlClient.SqlCommand
>
> =A0 =A0 =A0 =A0 With cmdSampling
> =A0 =A0 =A0 =A0 =A0 =A0 .CommandType =3D Data.CommandType.StoredProcedure
>
> =A0 =A0 =A0 =A0 =A0 =A0 .CommandText =3D "GetSampling"
> =A0 =A0 =A0 =A0 =A0 =A0 .Connection =3D conn
>
> =A0 =A0 =A0 =A0 =A0 =A0 .Parameters.AddWithValue("@mod",
> DropDownList1.SelectedValue)
> =A0 =A0 =A0 =A0 =A0 =A0 .Parameters.AddWithValue("@Button" Button10)
> =A0 =A0 =A0 =A0 =A0 =A0 .Parameters.AddWithValue("@FromDate", FromDte.Text=
)
> =A0 =A0 =A0 =A0 =A0 =A0 .Parameters.AddWithValue("@ToDate", ToDTE.Text)
>
> =A0 =A0 =A0 =A0 =A0 =A0 Response.Redirect("SamplingReport.aspx")
> =A0 =A0 =A0 =A0 End With
> =A0 =A0 End Sub
>
> You are trying to use the Button rather than either the Button.text or
> Button.clientid.
>
> You should turn option strict and option explicit on. =A0If you do then yo=
u
> will get much more meaningful error messages before you attempt to test.
>
> Hope this helps
> LLoyd Sheen- Hide quoted text -
>
> - Show quoted text -
Thanks got it now!