Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8865687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:34:42+00:00 2026-06-14T16:34:42+00:00

on a page in my application when the submit button is hit, the information

  • 0

on a page in my application when the submit button is hit, the information from the form above is to be stored into the database. I am getting this error when I run the program, but if I am to use breakpoints and copy the SQLtext string then paste this code into a new query on the DB manager it works. The error always says the following, but “Speed” is different depending on the value from ddlDrugs (for example, if we selected Alcohol, the error would say Conversion from string “Alcohol” to type ‘Integer’ is not valid) :

Conversion from string "Speed" to type 'Integer' is not valid. 

Does anyone see why this is happening? ddlDrugs is a dropdown in which is populated using a post back triggered when ddlDrugType is changed. Listed below first is the sub when the submit button is hit, and below that the function that binds the dropdown.

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmit.Click
    Dim objGetConnInfo As New ConnInfo
    Dim strConn As String
    strConn = objGetConnInfo.GetConnString
    Dim objConn As SqlConnection
    objConn = New SqlConnection(strConn)
    Dim myCmd As SqlCommand
    myCmd = New SqlCommand
    myCmd.Connection = objConn
    myCmd.CommandType = CommandType.Text
    Dim ds As SqlClient.SqlDataReader
    objConn.Open()
    Dim fName As String = txtfName.Text
    Dim lName As String = txtlName.Text
    Dim DOB As String = ddlDOBmonth.SelectedValue & "/" & ddlDOBday.SelectedValue & "/" & ddlDOByear.SelectedValue
    Dim sexChoice As Integer = rdoSex.SelectedIndex
    Dim sex As String
    If sexChoice = 0 Then
        sex = "m"
    ElseIf sexChoice = 1 Then
        sex = "f"
    End If
    Dim SSN As String = txtSSN.Text
    Dim address As String = txtAddress.Text
    Dim city As String = txtCity.Text
    Dim state As String = ddlState.SelectedValue
    Dim zip As String = txtZip.Text
    Dim phone As String = txtPhone1.Text
    Dim cellPhone As String = txtPhone2.Text
    Dim altPhone As String = txtPhone3.Text
    Dim EC As String = txtECname.Text
    Dim relationshipIndex As Integer = ddlECrelationship.SelectedValue
    myCmd.CommandText = "Select Name from Relationships where ID = " & relationshipIndex
    Dim relationship As String = myCmd.ExecuteScalar

    Dim ECphone As String = txtECphone.Text
    Dim findRRindex As Integer = ddlHowRR.SelectedValue
    myCmd.CommandText = "Select Name from foundRR where ID =" & findRRindex
    Dim findRR As String = myCmd.ExecuteScalar
    Dim rush As String
    If chkRush.Checked = True Then
        rush = "1"
    Else
        rush = "0"
    End If

    Dim reason As String = txtReason.Text
    Dim drugType As String = ddlDrugType.SelectedValue
    Dim drugIndex As Integer = ddlDrug.SelectedValue
    myCmd.CommandText = "Select Drug from " & drugType & " where Id = " & drugIndex
    Dim drugObj As Object = myCmd.ExecuteScalar
    Dim drug As String = ddlDrug.SelectedItem.Text

    Dim previous As String = txtPrevTreatment.Text
    Dim dateCompleted As String = ddlDOCmonth.SelectedValue & "/" & ddlDOCdate.SelectedValue & "/" & ddlDOCyear.SelectedValue
    Dim treatmentRep As String = txtTreatmentRep.Text
    Dim test As String = ddlDrug.SelectedValue



    '                        insert into Clients values ('mike','abramowitz','9/12/1986', 'm', 187664309, '2132 mather way',                               'elkins park', 'pa', 19027, '2222222222','3333', '4', 'dad', 'mom',                                                            '55', 'magic', 0, 'need it', 'drug type',                                              'pot', 'none', '9/12/1988', 'tim')
    Dim SQLtext As String = "exec insertClient '" & fName & "','" & lName & "','" & DOB & "', '" & sex & "'," & SSN & ", '" & address & "', '" & city & "', '" & state & "', " & zip & ", '" & phone & "','" & cellPhone & "', '" & altPhone & "', '" & EC & "', '" & relationship & "', '" & ECphone & "', '" & findRR & "'," & rush & ", '" & reason & "', ' " & drugType & "','" & drug & "', '" & previous & "', ' " & dateCompleted & "', '" & treatmentRep & "')"



    Dim clientID As Integer = myCmd.ExecuteScalar
    objConn.Close()
    myCmd.Dispose()


End Sub

Binding the dropdown on postback

    Protected Sub ddlDrugType_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
    Dim objGetConnInfo As New ConnInfo
    Dim strConn As String
    strConn = objGetConnInfo.GetConnString
    Dim objConn As SqlConnection
    objConn = New SqlConnection(strConn)
    Dim myCmd As SqlCommand
    myCmd = New SqlCommand
    myCmd.Connection = objConn
    myCmd.CommandType = CommandType.Text
    Dim ds As SqlClient.SqlDataReader
    myCmd.CommandText = "Select Id, Drug from " & ddlDrugType.SelectedValue
    objConn.Open()
    ds = myCmd.ExecuteReader
    ddlDrug.DataSource = ds
    ddlDrug.DataTextField = "Drug"
    ddlDrug.DataValueField = "Id"
    ddlDrug.DataBind()
    ds.Close()

    objConn.Close()

    myCmd.Dispose()


End Sub

and here is the detailed error

System.InvalidCastException was unhandled by user code

HResult=-2147467262
Message=Conversion from string “Speed” to type ‘Integer’ is not valid.
Source=Microsoft.VisualBasic
StackTrace:
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(Object Value)
at RR.NewCustomer.btnSubmit_Click(Object sender, EventArgs e) in C:\Users\Administrator\Documents\Visual Studio 2010\Projects\RR\RR\NewCustomer.aspx.vb:line 276
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException: System.FormatException
HResult=-2146233033
Message=Input string was not in a correct format.
Source=Microsoft.VisualBasic
StackTrace:
at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat)
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
InnerException:

edit: here is the code for the actual dropdowns

<asp:dropdownlist style="Z-INDEX: 0" id="ddlDrugType" 
                                OnSelectedIndexChanged="ddlDrugType_SelectedIndexChanged" runat="server" 
                                Height="16px" ViewStateMode="Enabled" AutoPostBack="True"></asp:dropdownlist>

<asp:dropdownlist style="Z-INDEX: 0" id="ddlDrug" runat="server"></asp:dropdownlist>

Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:34:43+00:00Added an answer on June 14, 2026 at 4:34 pm

    Can you post the html code for ddlDrug. I am suspecting you have something like

    <option selected="selected" value="Speed">Speed</option>
    <option value="Alchol">Alchol</option>
    

    Instead you should have some sort of ID for the value.

    or you need to change

    Dim drugIndex As Integer = ddlDrug.SelectedValue
    

    to

    Dim drugIndex As String = ddlDrug.SelectedValue
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Spring application when i click on the submit button on my form
I have a Razor/ASP/MVC3 web application with a form and a Submit button, which
Single Application Page Asp.net MVC 4 temlplate uses default database to check Login and
I have an application page. I want to click a button to pop out
<form action =/submit-page/ method='post' class=editable> <fieldset> <select name=status id='status'> <option value=Submitted>Submitted</option> <option value=Canceled>Canceled</option> <option
My result tables/images will be displayed in the same page. But the submit button
it should works but hitting the submit button redirect my page to http://localhost:8082/sign (http://localhost:8082
I have a number of auto-complete fields on my page with a submit button.
I made a form in my PHP / jQuery Mobile web application with this
I am doing a registration page for my application.For this I need to insert

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.