Datatype error from <asp:TextBox> Input string was not in a correct format.

S

sean

Hi There,

I am trying to make the transition from asp to asp.net, I have a stored
procedure that accepts an Integer parameter, when I pass the value from the
web form into the function I receive an error. I have tried the convert the
value using Cint (not sure if it is legal in ado.net) but I still get the
same error message.

Could someone help me out with the syntax please?

Sean

!-- code snippet

Dim intProductID as Integer
intProductID = Cint(txtProductID.Text)
Dim myConnection as New
SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
myConnection.Open()
Dim myCommand As New SqlCommand("ProductsAdd", myConnection)
myCommand.CommandType = CommandType.StoredProcedure

Dim pProductID As New SqlParameter("@ProductID", SqlDbType.Int,4)
pProductID.Value = intProductID
myCommand.Parameters.Add(pProductID)

myCommand.ExecuteNonQuery()
 
S

sean

HI Bin,

I am entering an number into a textbox, I am not sure how to do it in .net,
can you give me some syntax help please.

Sean
 
G

Guest

You can use try catch block to handle the exception
Try
intProductID = Cint(txtProductID.Text
Catch e as exceptio
'The text is not a valid number. you can either display the exception or just set the value to
txtProductID.Text =
intProductID =
End Tr

Bin Song, MC

----- sean wrote: ----

HI Bin

I am entering an number into a textbox, I am not sure how to do it in .net
can you give me some syntax help please

Sea
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top