insert dropdownlist value into database on button click


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:

'Insert


    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
        dbCommand.Parameters.Add(dbParam_role)
        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
        dbCommand.Parameters.Add(dbParam_level)
        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
        dbCommand.Parameters.Add(dbParam_category)
        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
        dbCommand.Parameters.Add(dbParam_material)
        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
        dbCommand.Parameters.Add(dbParam_location)
        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
        dbCommand.Parameters.Add(dbParam_section)

        Dim rowsAffected As Integer = 0
        dbConnection.Open
        Try
            rowsAffected = dbCommand.ExecuteNonQuery

        Finally
            dbConnection.Close
        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
LVL 3
tnapolitanoAsked:
Who is Participating?
 
EE_AutoDeleterConnect With a Mentor Commented:
tnapolitano,
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.

EE_AutoDeleter
0
 
tnapolitanoAuthor Commented:
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;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.