peebman2000
Programmer
Okay guys, this is vb code, that i'm struggleing with. I have a dropdownlist called DropDownlist1 and I'm trying to insert what ever value the user selects from the dropdown list into my database. I"m getting errors, and I know I have the dropdownlist coded wrong somehow, but I don't know how to code it right. (I'm researching how online). The error i'm getting is "'DropDownlist1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value ", does any one see what i'm doing wrong?
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
txtnominator.Text = " "
txtdor.Text = " "
txtaddress.Text = " "
txtcity.Text = ""
txtstate.Text = " "
txtzip.Text = " "
txtphonenumberevening.Text = " "
txtphonenumberdaytime.Text = " "
txtphonenumbercell.Text = " "
txtaward.Text = " "
txtnameofrecipient.Text = " "
txtbusiness.Text = " "
txtrecaddress.Text = " "
txtreccity.Text = " "
txtrecstate.Text = " "
txtreczip.Text = " "
DropDownlist1.SelectedValue = " "
txtbirthday.Text = " "
txtretirement.Text = " "
txtanniversary.Text = " "
txtdateaward.Text = " "
txtemail.Text = " "
txtcomments.Text = " "
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dataadapter As SqlDataAdapter
Dim datacommand As SqlCommand
Dim dataset As DataSet
dataadapter = New SqlDataAdapter
datacommand = New SqlCommand
dataset = New DataSet
datacommand.CommandText = "Insert INTO AwardForm (" & _
"Name_of_Nominator, " & _
"Date_of_Request, " & _
"Address_of_Nominator, " & _
"City, State, " & _
"Zip_Code, " & _
"Phone_Evening, " & _
"Phone_Daytime, " & _
"Phone_Cell, " & _
"Type_of_Award, " & _
"Name_of_Recipient, " & _
"Businesss_of_Org, " & _
"Address_of_Recipient, " & _
"Reci_city, " & _
"Reci_State, " & _
"Reci_Zip, " & _
"Delivery_of_Award, " & _
"Birthday_Cert, " & _
"Retiremnt_Cert, " & _
"Anniversary_Cert, " & _
"Date_of_Award, " & _
"Nominator_email, " & _
"Additional_comm)" & _
"values ('" & txtnominator.Text & "','" & _
"'" & txtdor.Text & "','" & _
"'" & txtaddress.Text & "','" & _
"'" & txtcity.Text & "','" & _
"'" & txtstate.Text & "','" & _
"'" & txtzip.Text & "','" & _
"'" & txtphonenumberevening.Text & "','" & _
"'" & txtphonenumberdaytime.Text & "','" & _
"'" & txtphonenumbercell.Text & "','" & _
"'" & txtaward.Text & "','" & _
"'" & txtnameofrecipient.Text & "','" & _
"'" & txtbusiness.Text & "','" & _
"'" & txtrecaddress.Text & "','" & _
"'" & txtreccity.Text & "','" & _
"'" & txtrecstate.Text & "','" & _
"'" & txtreczip.Text & "','" & _
"'" & DropDownlist1.SelectedValue & "','" & _
"'" & txtbirthday.Text & "','" & _
"'" & txtretirement.Text & "','" & _
"'" & txtanniversary.Text & "','" & _
"'" & txtdateaward.Text & "','" & _
"'" & txtemail.Text & "','" & _
"'" & txtcomments.Text & "')"
datacommand.Connection = New SqlConnection(ConfigurationManager.ConnectionStrings("GovAppConnectionString").ToString)
'datacommand.Connection = New SqlConnection(WebConfigurationManager.ConnectionStrings("GovAppConnectionString").ToString)
datacommand.Connection.Open()
Try
datacommand.ExecuteNonQuery()
Response.Write("data was entered")
Catch ex As Exception
Response.Write("data not entered")
End Try
datacommand.Connection.Close()
End Sub
End Class
Parameter name: value ", does any one see what i'm doing wrong?
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
txtnominator.Text = " "
txtdor.Text = " "
txtaddress.Text = " "
txtcity.Text = ""
txtstate.Text = " "
txtzip.Text = " "
txtphonenumberevening.Text = " "
txtphonenumberdaytime.Text = " "
txtphonenumbercell.Text = " "
txtaward.Text = " "
txtnameofrecipient.Text = " "
txtbusiness.Text = " "
txtrecaddress.Text = " "
txtreccity.Text = " "
txtrecstate.Text = " "
txtreczip.Text = " "
DropDownlist1.SelectedValue = " "
txtbirthday.Text = " "
txtretirement.Text = " "
txtanniversary.Text = " "
txtdateaward.Text = " "
txtemail.Text = " "
txtcomments.Text = " "
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dataadapter As SqlDataAdapter
Dim datacommand As SqlCommand
Dim dataset As DataSet
dataadapter = New SqlDataAdapter
datacommand = New SqlCommand
dataset = New DataSet
datacommand.CommandText = "Insert INTO AwardForm (" & _
"Name_of_Nominator, " & _
"Date_of_Request, " & _
"Address_of_Nominator, " & _
"City, State, " & _
"Zip_Code, " & _
"Phone_Evening, " & _
"Phone_Daytime, " & _
"Phone_Cell, " & _
"Type_of_Award, " & _
"Name_of_Recipient, " & _
"Businesss_of_Org, " & _
"Address_of_Recipient, " & _
"Reci_city, " & _
"Reci_State, " & _
"Reci_Zip, " & _
"Delivery_of_Award, " & _
"Birthday_Cert, " & _
"Retiremnt_Cert, " & _
"Anniversary_Cert, " & _
"Date_of_Award, " & _
"Nominator_email, " & _
"Additional_comm)" & _
"values ('" & txtnominator.Text & "','" & _
"'" & txtdor.Text & "','" & _
"'" & txtaddress.Text & "','" & _
"'" & txtcity.Text & "','" & _
"'" & txtstate.Text & "','" & _
"'" & txtzip.Text & "','" & _
"'" & txtphonenumberevening.Text & "','" & _
"'" & txtphonenumberdaytime.Text & "','" & _
"'" & txtphonenumbercell.Text & "','" & _
"'" & txtaward.Text & "','" & _
"'" & txtnameofrecipient.Text & "','" & _
"'" & txtbusiness.Text & "','" & _
"'" & txtrecaddress.Text & "','" & _
"'" & txtreccity.Text & "','" & _
"'" & txtrecstate.Text & "','" & _
"'" & txtreczip.Text & "','" & _
"'" & DropDownlist1.SelectedValue & "','" & _
"'" & txtbirthday.Text & "','" & _
"'" & txtretirement.Text & "','" & _
"'" & txtanniversary.Text & "','" & _
"'" & txtdateaward.Text & "','" & _
"'" & txtemail.Text & "','" & _
"'" & txtcomments.Text & "')"
datacommand.Connection = New SqlConnection(ConfigurationManager.ConnectionStrings("GovAppConnectionString").ToString)
'datacommand.Connection = New SqlConnection(WebConfigurationManager.ConnectionStrings("GovAppConnectionString").ToString)
datacommand.Connection.Open()
Try
datacommand.ExecuteNonQuery()
Response.Write("data was entered")
Catch ex As Exception
Response.Write("data not entered")
End Try
datacommand.Connection.Close()
End Sub
End Class