473,320 Members | 1,856 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,320 software developers and data experts.

error message.

Hi,

I am running a stored procedure when the user selects an
item from a combobox (combobox1). This stored procuedure
gets values based on what was just chosen by the user in
combobox1 and enters these values in combobox2.

However i keep encountering the following error message
which i do not know how to resolve. Combobox2 does not
get populated due to this error....

Specified cast is not valid.

here is my code....
'Display the caravan length based on the caravan name
selected.
Dim Cn As New SqlConnection("initial
catalog=TestCaraDBmsde;integrated security=SSPI;persist
security info=False;workstation id=USER;packet size=4096")
Dim cmdLength As New SqlCommand("SPSelLengths", Cn)
cmdLength.CommandType =
CommandType.StoredProcedure

'declare the parameters
cmdLength.Parameters.Add("@CaraName",
SqlDbType.Char, 50)
'now set the values
cmdLength.Parameters("@CaraName").Value =
CBoxDisCaraNames.SelectedItem
CBoxCaraLength.Items.Clear()
CBoxCaraLength.Text = ""

Try
Cn.Open()
Dim reader3 As SqlDataReader
reader3 = cmdLength.ExecuteReader()
While reader3.Read
CBoxCaraLength.Items.Add
(reader3.GetSqlString(0))
End While
Catch ex As Exception
MsgBox(ex.Message)
Finally
Cn.Close()
End Try
End Sub

can anyone help me resolve this?
Jul 21 '05 #1
1 1066
Is it possible that for some rows

reader3.GetSqlString(0)

Returns a Null Value?

To help you track down which line the error is actually happening on:

1) Debug Menu > Exceptions
2) Find "InvalidCastException" in the tree
3) Select "Break into the debugger" for this exception when it is thrown.

This should help you narrow down the possibilities.

Also I'd recommend switching "Option Strict" on for your project. This will
force you to be a little bit more consious about what variables you assign
to other types of variables.

Hope this helps,

Trev.
"Angelina" <an*******@discussions.microsoft.com> wrote in message
news:0e****************************@phx.gbl...
Hi,

I am running a stored procedure when the user selects an
item from a combobox (combobox1). This stored procuedure
gets values based on what was just chosen by the user in
combobox1 and enters these values in combobox2.

However i keep encountering the following error message
which i do not know how to resolve. Combobox2 does not
get populated due to this error....

Specified cast is not valid.

here is my code....
'Display the caravan length based on the caravan name
selected.
Dim Cn As New SqlConnection("initial
catalog=TestCaraDBmsde;integrated security=SSPI;persist
security info=False;workstation id=USER;packet size=4096")
Dim cmdLength As New SqlCommand("SPSelLengths", Cn)
cmdLength.CommandType =
CommandType.StoredProcedure

'declare the parameters
cmdLength.Parameters.Add("@CaraName",
SqlDbType.Char, 50)
'now set the values
cmdLength.Parameters("@CaraName").Value =
CBoxDisCaraNames.SelectedItem
CBoxCaraLength.Items.Clear()
CBoxCaraLength.Text = ""

Try
Cn.Open()
Dim reader3 As SqlDataReader
reader3 = cmdLength.ExecuteReader()
While reader3.Read
CBoxCaraLength.Items.Add
(reader3.GetSqlString(0))
End While
Catch ex As Exception
MsgBox(ex.Message)
Finally
Cn.Close()
End Try
End Sub

can anyone help me resolve this?

Jul 21 '05 #2

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

Similar topics

10
by: | last post by:
I am accessing the same error-containing ASP page on an ISP server using w2k IE6 but with different effect. On the first computer I get several line of HTML outputed by ASP, shown correctly by...
9
by: Mairhtin O'Feannag | last post by:
Hello, We have two machines we wish to use DPF. They are both RH ES 2.1, with DB2 8.2. I read the documentation CAREFULLY, and added the following line to my db2nodes.cfg file : 1 egret 0
6
by: Squirrel | last post by:
I have a command button on a subform to delete a record. The only statement in the subroutine is: DoCmd.RunCommand acCmdDeleteRecord The subform's recordsource is "select * from tblVisit order...
8
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
10
by: Shawn | last post by:
JIT Debugging failed with the following error: Access is denied. JIT Debugging was initiated by the following account 'PLISKEN\ASPNET' I get this messag in a dialog window when I try to open an...
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.