This is a migrated thread and some comments may be shown as answers.

[Solved] RadComboBox Input string was not in a correct format.

2 Answers 378 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 28 Apr 2009, 02:36 PM
I have a radcombobox that I want the user to either select from or type in a new item.  If the item is new I want them to click a button to add it to the list permanently.  The text is entered into the RadComboBox fine and then once the focus is removed from the RCB I get the error below.  Can some point me in the right direction. 

aspx.vb

 

Protected Sub ItemsRequested(ByVal o As Object, ByVal e As RadComboBoxItemsRequestedEventArgs) Handles RCBClient.ItemsRequested

 

 

Try

 

RCBClient.Items.Clear()

 

Dim selectCommand As New SqlCommand("GetClients", myConnection)

 

selectCommand.CommandType = CommandType.StoredProcedure

selectCommand.Parameters.AddWithValue(

"@CN", e.Text)

 

 

Dim adapter As New SqlDataAdapter(selectCommand)

 

 

Dim DT As New DataTable()

 

adapter.Fill(DT)

RCBClient.DataTextField =

"Client"

 

RCBClient.DataValueField =

"ClientID"

 

RCBClient.DataSource = DT

RCBClient.DataBind()

 

Catch

 

 

End Try

 

 

End Sub

 

 

Protected Sub btnLoad_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoad.Click

 

 

Using selectCommand As New SqlCommand("CreateClient", myConnection)

 

selectCommand.CommandType = CommandType.StoredProcedure

selectCommand.Parameters.AddWithValue(

"@CN", RCBClient.Text)

 

myConnection.Open()

 

Using reader As SqlDataReader = selectCommand.ExecuteReader

 

 

While reader.Read

 

Build_CustomerRep(reader(

"CID"))

 

Build_Facility(reader(

"CID"))

 

 

End While

 

 

End Using

 

myConnection.Close()

 

End Using

 

 

End Sub

.aspx

 

 

<tr><td>Client:</td>

 

 

 

 

 

<td><Telerik:RadComboBox ID="RCBClient" EnableEmbeddedSkins="false" Skin="Default" runat="server" ShowMoreResultsBox="False" EnableLoadOnDemand="True" OnItemsRequested="ItemsRequested" AutoPostBack="true" >

 

 

 

 

 

<CollapseAnimation Type="OutExpo" Duration="200"></CollapseAnimation>

 

 

</Telerik:RadComboBox>

 

 

</td>

 

 

 

 

 

<td><asp:Button runat="server" ID="btnLoad" Text="Create New" /></td>

 

 

 

 

 

</tr>

Error:

 

 

Server Error in '/' Application.

Input string was not in a correct format.

 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[FormatException: Input string was not in a correct format.]
   Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) +717374
   Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) +118

[InvalidCastException: Conversion from string "" to type 'Integer' is not valid.]
   Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) +721303
   Mistras_Admin_ClientSetup.RCBClient_SelectedIndexChanged(Object o, RadComboBoxSelectedIndexChangedEventArgs e) +87
   Telerik.Web.UI.RadComboBox.OnSelectedIndexChanged() +183
   System.Web.UI.Page.RaiseChangedEvents() +89
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2777

 


Version Information: Microsoft .NET Framework Version:2.0.50727.3074; ASP.NET Version:2.0.50727.3074

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 Apr 2009, 02:03 PM
Hi John,

I think the issue is due to passing empty value to SqlCommand.So please try adding empty condition checking for e.Text (ie e.Text!= String.Empty),before passing it as parameter value.

Thanks,
Shinu.
0
John
Top achievements
Rank 1
answered on 29 Apr 2009, 08:02 PM
I understand what you are saying except I get the error when I enter text into the combobox that is not in the DB.
Tags
ComboBox
Asked by
John
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
John
Top achievements
Rank 1
Share this question
or