473,383 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Error: Cast From String to type Integer not valid

I need some help. I have the following code:
cmSQL = New SqlCommand("nf_AddPurchaseOrder", cnSQL)
cmsql.CommandType = CommandType.StoredProcedure
cmsql.Parameters.Add("@PurchaseOrderId", sqldbtype.varchar, 10,
"OrderNo").Value = txtPONum.Text
cmsql.Parameters.Add("@OrderDesc", sqldbtype.VarChar , 50 ,
"OrderDesc").Value = txtOrderDescription.text
cmsql.Parameters.Add("@SupplierId", sqldbtype.Int , "SupplierId").Value =
s.SupplierId
Dim b as Program
b = cmbPrograms.SelectedItem
cmsql.Parameters.Add("@ProgramId", sqldbtype.Int , "ProgramId").Value =
b.ProgramId

When the code hits either the SupplierId or the ProgramId line I get the
following error:
Cast from String "SupplierId" to type 'Integer' is not valid
My problem is that the stored procedures parameters are Int, the values I'm
passing in are also Integers. So not sure where the heck this error is coming
from. Thanks for any help.
Michael Lee
Nov 21 '05 #1
2 4554
Michael,

VBNet has those nice conversions methods.

dim a as integer = Cint("1") is all you have to do to make from a string
containing only numbers and by instance decimal points a nice integer.

I hope this helps,

Corn
Nov 21 '05 #2
Hi Cor,
Thanks for the reply. I just found the problem, it was my mistake. If I
change the following code:
cmsql.Parameters.Add("@SupplierId", sqldbtype.Int , "SupplierId").Value =
s.SupplierId
TO:
cmsql.Parameters.Add("@SupplierId", sqldbtype.Int).Value = s.SupplierId

It works fine. I had gotten the wrong overloaded method.
Thanks for the reply.
Michael

"Cor Ligthert" wrote:
Michael,

VBNet has those nice conversions methods.

dim a as integer = Cint("1") is all you have to do to make from a string
containing only numbers and by instance decimal points a nice integer.

I hope this helps,

Corn

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kakaiya | last post by:
Error message: An unhandled exception of type 'System.InvalidCastException' occurred in test.dll Additional information: Specified cast is not valid. Public Class Form1 Inherits...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
8
by: Razak | last post by:
Hi, I have a class which basically do Impersonation in my web application. From MS KB sample:- ++++++++++++++++++++code starts Dim impersonationContext As...
5
by: Alan Silver | last post by:
Hello, I have an ASP.NET page where I am grabbing an SqlDataReader and using it to populate some controls on the form. Amongst the fields pulled out of the table are two integer fields, which I...
4
by: Web Team | last post by:
Hi All, When I run the below code, I get error 'Specified cast is not valid' on line 163 Dim Address As OldInfra.BS7666.Address = BS7666AddressCollection.GetSingleAddress(str_UPRN) 164...
4
by: Sparky Arbuckle | last post by:
I am looping through a listbox collection to build a SQL string that will be used to delete items from a database. I have tried many variances of the code below but have had no luck. The code below...
2
by: Vikram | last post by:
in my asp.net app, i get following two errors some times, these errors occasionally occurs please let me know if anyone has any idea why they occur Cast from string "" to type 'Integer' is not...
33
by: Martin Jørgensen | last post by:
Hi, In continuation of the thread I made "perhaps a stack problem? Long calculations - strange error?", I think I now got a "stable" error, meaning that the error always seem to come here now...
13
by: lithoman | last post by:
I'm stumped here. I run the procedure Batch_Select against the database with @ID=18 and I get the expected data. When it loads into a SqlDataReader, it gets messed up somehow. Initially, after the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.