Wrox Programmer Forums
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 24th, 2005, 02:13 PM
Registered User
 
Join Date: Feb 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default ADO Error -2147217913

Hi,
     I need help to figure out what to do about this ADO error. The desciption for the error code #
-2147217913 is "Invalid character value for cast specification". I'm sending a date value from a date picker object to a parameterized stored procedure where the date = the date of birth value in the accounts table. That is when I recieve the above error.

The code I use to open a recordset using the stored procedure below is:

dim strDOB as DTPicker

strDOB = me.dtpDOB

'Open the recordset object
objRS.Open "up_parmsel_test (" & strDOB & ")", _
       objConn, adOpenForwardOnly, adLockReadOnly, adCmdStoredProc


I've tried making the strDOB variable a Date data type and a String data type and I get the same error no matter which data type I use.

The code for the stored procedure is below:

ALTER PROCEDURE dbo.up_parmsel_test
    @DOB_DATE_DT DATETIME AS

-- I've also made the @DOB_Date_DT parameter above a VARCHAR data
-- type and once again, I get the same error.

DECLARE @SQL NVARCHAR(4000),
    @SQLWHERE NVARCHAR(1024)

SET @SQL = ''
SET @SQLWHERE = ''

SET @SQL = 'SELECT ACC_ACCTNUM_VC, ACC_FIRST_NAME_VC, ACC_LAST_NAME_VC
            FROM ACCOUNTS_T'

IF @DOB_Date_DT IS NOT NULL
        BEGIN
                SET @SQLWHERE = @SQLWHERE + '
                    ACCOUNTS_T.ACC_DOB_DATE_DT
                                        = ' + @DOB_Date_DT
        END

-- I've also casted it using the @DOB_Date_DT parameter to be a
-- VARCHAR AND I've converted it like the following
-- "CONVERT(NVARCHAR(10), @DOB_Date_DT,101)", but that also gave me
-- the same error.

IF @SQLWHERE <> ''
    SET @SQL = @SQL + ' WHERE ' + @SQLWHERE

--PRINT @SQL
EXEC sp_executesql @SQL
    WITH RECOMPILE


If I declare the @DOB_Date_DT and set it equal to the date in the DOB_DT field and run the code by itself without running it from VB, the stored procedure pulls up the requested data with no problems. It just doesn't work when calling the stored procedure through VB. I'm using VB 6.0 and SQL Server 2000. Please help! Thanks

Robert


 
Old March 2nd, 2005, 12:31 PM
Registered User
 
Join Date: Feb 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I figured it out. I had to put a single quote in the open recordset code in vb. The following code shows how it should have been , (represented by the bold, red, single quotes), compared to the way it was in my initial post:

'Open the recordset object
objRS.Open "up_parmsel_test ('" & strDOB & "')", _
       objConn, adOpenForwardOnly, adLockReadOnly, adCmdStoredProc






Similar Threads
Thread Thread Starter Forum Replies Last Post
Runtime error -'-2147217913 (80040e07) kavisundar Classic ASP Databases 0 May 16th, 2007 10:04 AM
ADO.NET error gb012993 BOOK: Beginning C# 2005 Databases 2 May 9th, 2007 03:10 AM
vba ado error weazy Excel VBA 2 June 13th, 2006 09:57 PM
Ado.Net Error digby_dog VB.NET 2002/2003 Basics 2 June 7th, 2005 04:29 AM
Oracle9i and ADO error?? philVT2000 Pro VB Databases 1 March 1st, 2005 11:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.