Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

Need help setting up cast...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JJ297 - 07 Apr 2008 15:47 GMT
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.ConnectionStrings("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
Lloyd Sheen - 07 Apr 2008 16:12 GMT
> Here's my stored procedure:
>
[quoted text clipped - 45 lines]
>
>        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
JJ297 - 07 Apr 2008 16:35 GMT
> > Here's my stored procedure:
>
[quoted text clipped - 55 lines]
>
> - 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.ConnectionStrings("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
Lloyd Sheen - 07 Apr 2008 17:24 GMT
On Apr 7, 11:12 am, "Lloyd Sheen" <a...@b.c> wrote:
> "JJ297" <nc...@yahoo.com> wrote in message
>
[quoted text clipped - 60 lines]
>
> - 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.ConnectionStrings("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
JJ297 - 07 Apr 2008 19:44 GMT
> On Apr 7, 11:12 am, "Lloyd Sheen" <a...@b.c> wrote:
>
[quoted text clipped - 111 lines]
>
> - Show quoted text -

Thanks got it now!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.