A
adams114
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
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