Invalid CastException with SqlDBType

Tech-Archive recommends: Fix windows errors by optimizing your registry

adams114_at_comcast.net
Date: 05/20/04


Date: Thu, 20 May 2004 11:15:05 -0700

I am having a strange problem with invalid type casts. I am trying to
update a MS SQL Database with a stored procedure. When I setup the
parameters collection for the command object I get a invalid cast
exception error:

Compiler Error Message: BC30311: Value of type 'Date' cannot be
converted to 'Integer'.

The real problem here is that the type in the database and the stored
prcedure aren't integers at all rather they are datetime types. No
matter what date format or information I pass to the parameter setting
up the date I get the error or a varient of it but all are trying to
cast it to an integer.

Here's my Code:
 Dim ConnectionString As String =
"server=(local);database=poolMaint;trusted_connection=true"
        dim CommandText as string = "insert_Ph_Calibrations_1"

        dim myConnection as new SqlConnection(ConnectionSTring)
        dim myCommand as new SqlCommand(CommandText, myConnection)
        dim workParam as new SqlParameter()

        myCommand.CommandType = CommandType.StoredProcedure

        ' setup the parameters for the stored procedure

        myCommand.Parameters.Add("@PhCalibration_ID_1",
SqlDBType.nchar, 1, "PhCalibration_ID_1")
        myCommand.Parameters.Add("@DateRecord_2", SqlDBType.DateTime,
datetime.now, "DateRecord_2")
        myCommand.Parameters.Add("@Tech_3", SqlDBType.nchar,
txtTech.text, "Tech_3")

        myCommand.Connection.Open()
        myCommand.ExecuteNonQuery()
        myCommand.Connection.Close()

Here's My Stored Procedure:

CREATE PROCEDURE [insert_PhCalibrations_1]
        (@PhCalibration_ID_1 [uniqueidentifier],
         @DateRecord_2 [datetime],
         @Tech_3 [char](16))

AS INSERT INTO [PoolMaint].[dbo].[PhCalibrations]
         ( [PhCalibration_ID],
         [DateRecord],
         [Tech])
 
VALUES
        ( @PhCalibration_ID_1,
         @DateRecord_2,
         @Tech_3)
GO

Any help you can offer me will be greatly appreciated as I have no
clue about this casting problem

jeremiah



Relevant Pages

  • Re: Invalid CastException with SqlDBType
    ... Add(string*, SqlDbType, int, string**) ... The DateTime.Now is trying to cast into a int. ... not in Sql set up the column as identity and let it seed itself. ... > update a MS SQL Database with a stored procedure. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Slow during INSERT binary data
    ... It does not look like blocking. ... I do the insert in a stored procedure which is called from a .NET program ... There is a 30 seconds timeout. ... it is very likely that some updates in SQL database need a push from my ...
    (microsoft.public.sqlserver.programming)
  • Re: Slow during INSERT binary data
    ... It does not look like blocking. ... I do the insert in a stored procedure which is called from a .NET program ... There is a 30 seconds timeout. ... it is very likely that some updates in SQL database need a push from my ...
    (microsoft.public.dotnet.framework.adonet)
  • How to detect if a merge replication is still running
    ... I have an application where a mobile device synchronizes with a SQL database. ... After the merge replication has completed I fire a stored procedure to ... know that Enterprise Manager will show the merge agent status as running. ...
    (microsoft.public.sqlserver.programming)
  • Access to SQL in Form
    ... I need to load a continuous form with data from a ... I have linked some of my tables to this SQL database, ... stored procedure as apposed to a normal query. ...
    (microsoft.public.access.formscoding)