Re: Variable definitions within a Case Statement

Discussion in 'ASP .Net' started by Patrice, May 13, 2004.

  1. Patrice

    Patrice Guest

    It just means that ds and l_parm1 are already declared above. This is not
    allowed (to avoid thinking you are using the outer ds variable while you are
    actually using a variable that uses the same name and that is declared in an
    inner block of code).

    Patrice

    "D. Franklyn" <> a écrit dans le message de
    news:...
    > Hello,
    >
    > In the code below I am setting up to query a SQL server
    > to bring back a company name. This code works in other
    > places but I only want to do it if my request.querystring
    > is "Company" I cant compile the code because it tell me
    > the Dim ds As New DataSet
    > and
    > Dim L_parm1 As New SqlParameter
    >
    > "hides a variable in an enclosing block"
    >
    > Does that mean I have to run this query and hold the
    > results in memory even if I know I don't need them???
    >
    > dfw
    >
    > **********************************************************
    > If Not Page.IsPostBack Then
    > Dim conn As SqlConnection = New

    SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
    >
    > '********************************Code for Affiliated

    Companies*****************************
    > Select Case Request.QueryString("pcp")
    > Case Is = "Company"
    > Dim N_Comp_ID As String
    > N_Comp_ID = Request.QueryString("cid")
    >
    > Dim ds As New DataSet
    > Dim L_parm1 As New SqlParameter _
    > ("@CompId", SqlDbType.Char, 4)
    > L_parm1.Direction = ParameterDirection.Input
    > L_parm1.Value = N_Comp_ID
    >
    > Dim daFund As New SqlDataAdapter
    > daFund.SelectCommand = New SqlCommand
    > daFund.SelectCommand.Connection = conn
    > daFund.SelectCommand.CommandText = "USP_Get_Company"
    > daFund.SelectCommand.CommandType = _
    > CommandType.StoredProcedure
    > daFund.SelectCommand.Parameters.Add(L_parm1)
    >
    > ds = New DataSet
    > daFund.Fill(ds, "CompRec")
    >
    > If ds.Tables("CompRec").Rows.Count = 1 Then
    > lblName.Text = ds.Tables("CompRec").Rows(0).Item(1)

    'CompanyName
    > Else
    > lblName.Text = "Company Not Found"
    > End If
    >
    > Case Else
    > Dim cmdLocalSelect As New

    SqlCommand("USP_Get_Companies", conn)
    > cmdLocalSelect.CommandType =

    CommandType.StoredProcedure
    > Dim ParamFundId As New SqlParameter _
    > ("@Fund_Id", SqlDbType.Char, 4)
    > ParamFundId.Direction = ParameterDirection.Input
    > ParamFundId.Value = Session("Fund_id")
    > cmdLocalSelect.Parameters.Add(ParamFundId)
    > conn.Open()
    > Dim drLocals As SqlDataReader
    > drLocals = cmdLocalSelect.ExecuteReader
    >
    > lbAfflComps.DataSource = drLocals
    > lbAfflComps.DataTextField = "Name"
    > lbAfflComps.DataValueField = "Empl_id"
    > lbAfflComps.DataBind()
    > drLocals.Close()
    > conn.Close()
    >
    > lbAfflComps.Visible = False
    > lblAfflLocals.Visible = False
    >
    > If Not IsDBNull(drLocals) Then
    > lbAfflComps.Visible = True
    > lbAfflComps.Visible = True
    > Else
    > lbAfflComps.Visible = False
    > lbAfflComps.Visible = False
    > End If
    > End Select
    >
    > .
    >
    >
    Patrice, May 13, 2004
    #1
    1. Advertising

  2. Thanks. I will redefine and Try again. That error message is a little misleading

    dfw
    =?Utf-8?B?REZyYW5rbHlu?=, May 13, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. colin
    Replies:
    3
    Views:
    571
  2. Replies:
    9
    Views:
    4,974
  3. Andy B
    Replies:
    1
    Views:
    586
    Andy B
    Jan 24, 2009
  4. vtbvtb
    Replies:
    0
    Views:
    627
    vtbvtb
    Sep 11, 2012
  5. vtb
    Replies:
    9
    Views:
    761
    rickman
    Sep 13, 2012
Loading...

Share This Page