Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Specified cast is not valid

Author  Topic 

Trevor
Starting Member

6 Posts

Posted - 2005-08-03 : 13:31:46
I am bringing in an ID threw my sql code in this store procedure

ALTER Proc sp_LOAD_DEALER @Dealer as varchar(100)
--sp_LOAD_DEALER Jay
as
select DealerName as DealerName, DealerID as DealerID,'<a href="AdminEdit.aspx?scid=' + cast(DealerID as varchar(100)) + '" border=0>Edit</a>' [Edit]
From Dealers
Where (DealerName LIKE + @Dealer + '%')

Which then redirects to my vbpage that loads the Id in the page load event.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PageLock()
'Response.Write(Request.QueryString("scid"))
LoadFields(Request.QueryString("scid"))

Then gets loaded to the LoadFields sub routine

Private Sub LoadFields(ByVal DealerID As String)

mycommand = New SqlCommand("sp_LOAD_FIELDS '" & DealerID.ToString & "'", myconn)
DealerNameText = mydataset.Tables(0).Rows(0).Item(1)
End Sub

and then get loaded from there into this stored procedure

alter proc sp_LOAD_FIELDS @DealerID varchar(100)
as
--sp_LOAD_FIELDS 'B3AC72B0-A538-4657-A8A3-4A3CA4D55589'

Select *, DealerID
from DEALERS
where DealerID = @DealerID

The problem is that I keep getting an Invalid cast error. When I print to the screen before loading to the second stored procedure, the value appears as I want it. I trying to figure out if the problem is the second stored procedure or the vb code that loads value into the stored procedure. Bear with me, I am learning as I go.
Thanks.

Kristen
Test

22859 Posts

Posted - 2005-08-03 : 16:00:41
Create a temporary "debugging" table, and INSERT into if from each of your SProcs (Name of SProc, GetDate() and and useful data)

Then you can have a look in the Debugging table and see what you got

(Slight snag if you get rolled back as the Debugging data will be rolled back too)

2) Use SQL Profiler to see the exact syntax that is being passed by the Application to SQL Server and then try than manually for errors etc.

3) You ain't going to score ANY marks for this gem!!

Select *, DealerID
from DEALERS
where DealerID = @DealerID

Does SELECT * include DealerID? I thought so

Will SELECT * potentially return columns you don't need, and might be huge TEXT columns, in the future? Yup, thought so.

Change "from DEALERS" to "from dbo.DEALERS" - its slightly more efficient for SQL to always explicitly reference the owner of the object.

Kristen
Go to Top of Page
   

- Advertisement -