dropdown box issue

Discussion in 'C#' started by wagae, Apr 2, 2007.

  1. #1
    Hi everyone
    Please have a look, i have this method, i know for sure that @ValID , has a value BUT i get an error saying the stored procedure is expecting that value....am i missing something?
    here is the line that adds the parameter, @ValID is the expected parameter,it has a value, but i get "stored proc is expecting a value that was not supplied error"

    oCMD.Parameters.AddWithValue("@ValID", CInt(ddl_MyValue))

    here is the code

    Private Sub MyDescriptions(ByVal ddl_MyValue As Integer)
    Dim oConn As SqlConnection
    Dim oCMD As SqlCommand
    Dim oDR As SqlDataReader
    Dim oLI As System.Web.UI.WebControls.ListItem

    ddl_MyOptions.Items.Clear()
    oConn = New SqlConnection(Conn)

    oCMD = New SqlCommand("Execute ReturnMyDescriptions")
    oCMD.Parameters.AddWithValue("@ValID", CInt(ddl_MyValue))
    oCMD.Connection = oConn
    oConn.Open()
    oDR = oCMD.ExecuteReader
    If oDR.HasRows Then

    While oDR.Read
    oLI = New System.Web.UI.WebControls.ListItem()
    oLI.Value = CStr(oDR("sDescription")).Trim
    oLI.Text = CStr(oDR("sDescription")).Trim
    ddl_MyOptions.Items.Add(oLI)
    End While
    Else
    'nothing
    End If
    oDR.Close()
    oConn.Close()
    End Sub


    Please help
     
    wagae, Apr 2, 2007 IP
  2. kajakske

    kajakske Well-Known Member

    Messages:
    139
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    165
    #2
    ddl_MyValue is a dropdownlist ?

    Shouldn't you use ddl_MyValue.SelectedValue instead then ?
     
    kajakske, Apr 6, 2007 IP
  3. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #3
    A few tips: even thought it's available to you... don't use Obj.Trim - use Trim(Obj) because this doesn't throw errors even if the obj doesn't exist ;)

    Also - instead of Directly casting an integer, try to "tryCast" it: CInt(ddl_MyValue) should be:
    Dim MyValue as integer
    If Integer.TryParse(ddl_MyValue, MyValue) then
    ... continue because its an int

    also, are yo udirectly creating an instance of a WebContro List item? (Dim oLI As System.Web.UI.WebControls.ListItem)

    Also, try to Enumerate vs. Iteration or Looping with a While or Do... this way you can cast your items inside the loop as the innerloop item that your looping and directly pull i'ts properties :)
     
    ccoonen, Apr 6, 2007 IP