473,786 Members | 2,462 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error: Cast From String to type Integer not valid

I need some help. I have the following code:
cmSQL = New SqlCommand("nf_ AddPurchaseOrde r", cnSQL)
cmsql.CommandTy pe = CommandType.Sto redProcedure
cmsql.Parameter s.Add("@Purchas eOrderId", sqldbtype.varch ar, 10,
"OrderNo").Valu e = txtPONum.Text
cmsql.Parameter s.Add("@OrderDe sc", sqldbtype.VarCh ar , 50 ,
"OrderDesc").Va lue = txtOrderDescrip tion.text
cmsql.Parameter s.Add("@Supplie rId", sqldbtype.Int , "SupplierId").V alue =
s.SupplierId
Dim b as Program
b = cmbPrograms.Sel ectedItem
cmsql.Parameter s.Add("@Program Id", sqldbtype.Int , "ProgramId").Va lue =
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 4576
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.Parameter s.Add("@Supplie rId", sqldbtype.Int , "SupplierId").V alue =
s.SupplierId
TO:
cmsql.Parameter s.Add("@Supplie rId", 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
3398
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 System.Windows.Forms.Form Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
6
4753
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 appreciated. Thanks in advance
8
9469
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 System.Security.Principal.WindowsImpersonationContext Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity
5
1900
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 am trying to cast as strings so they can be displayed in a Literal control. I am using the following code (heavily edited for clarity) ... if (dtrDilemmas.Read()) {
4
1354
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 Dim easting As Integer = Address.Easting
4
1840
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 gives an error: Cast from type 'ListItem' to type 'String' is not valid. When i do a response.write(s) the item at the top row displays correctly. Here is the code I am using:
2
1013
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 valid Object reference not set to an instance of an object
33
2871
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 (tried: visual studio 2005 + linux/macintosh gcc)... That's a pretty good thing. I think the error still appears using both gcc and visual studio 2005. Everything is standard C (ANSI C ?? I don't know the difference) - but since so many functions...
13
2864
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 reader.Read(), it has a row with 13 data columns, but they're all empty. So, my GetInt() function throws an error. When it jumps to the catch(), reader's columns then show the proper data. What gives? I have reader._data (which is the ID...
0
9496
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8989
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4066
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3669
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.