insert dropdownlist value into database on button click

Posted on 2006-06-04
Last Modified: 2008-01-09

I have a page with 3 ddl's and 3 textboxes. I want to insert the dropdownlist values and information entered into the textboxes into a database on button click.

When I launch the page I get: BC30311: Value of type 'System.Web.UI.WebControls.DropDownList' cannot be converted to 'String'

Here's my insert code:


    Function putMaterial(ByVal role As String, ByVal level As Integer, ByVal category As String, ByVal material As String, ByVal location As String, ByVal section As String) As Integer
        Dim connectionString As String = "server='(local)'; trusted_connection=true; database='Deputization'"
        Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)

        Dim queryString As String = "INSERT INTO [dp_material] ([Role], [Level], [Category], [Material], [Location], ["& _
"Section]) VALUES (@Role, @Level, @Category, @Material, @Location, @Section)"
        Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
        dbCommand.CommandText = queryString
        dbCommand.Connection = dbConnection

        Dim dbParam_role As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
        dbParam_role.ParameterName = "@Role"
        dbParam_role.Value = role
        dbParam_role.DbType = System.Data.DbType.StringFixedLength
        Dim dbParam_level As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
        dbParam_level.ParameterName = "@Level"
        dbParam_level.Value = level
        dbParam_level.DbType = System.Data.DbType.Int32
        Dim dbParam_category As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
        dbParam_category.ParameterName = "@Category"
        dbParam_category.Value = category
        dbParam_category.DbType = System.Data.DbType.StringFixedLength
        Dim dbParam_material As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
        dbParam_material.ParameterName = "@Material"
        dbParam_material.Value = material
        dbParam_material.DbType = System.Data.DbType.StringFixedLength
        Dim dbParam_location As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
        dbParam_location.ParameterName = "@Location"
        dbParam_location.Value = location
        dbParam_location.DbType = System.Data.DbType.StringFixedLength
        Dim dbParam_section As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
        dbParam_section.ParameterName = "@Section"
        dbParam_section.Value = section
        dbParam_section.DbType = System.Data.DbType.StringFixedLength

        Dim rowsAffected As Integer = 0
            rowsAffected = dbCommand.ExecuteNonQuery

        End Try

        Return rowsAffected
    End Function

Sub Button1_Click(sender As Object, e As EventArgs)

putMaterial(ddlRole, ddlLevel, ddlCategory, txtboxMaterial.Text, txtboxLocation.Text, txtboxSection.Text)

End Sub
Question by:tnapolitano
    LVL 3

    Author Comment

    Answered it myself.

    To determine the selected value in the DropDownList you would use the SelectedItem property or SelectedValue.

    row.item( "edName" ) = ddlUser.SelectedValue
    row.item( "edName" ) = ddlUser.SelectedItem.Value;

    Accepted Solution

    Because you have presented a solution to your own problem which may be helpful to future searches, this question is now PAQed and your points have been refunded.


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now