Hi everyone,

I have an InvalidCastException Error in my program. The program is that i try to insert an employee record into a database table after getting the details from a form. I've used Money data type is SQL Server for salary and SqlTypes.SqlDecimal data type in employee template class. i've used a stored procedure to pass the values and i add the basic value by passing a parameter by the method

Dim prm8 As SqlParameter = com.Parameters.Add("@basic", SqlDbType.Money)
            prm8.Direction = ParameterDirection.Input
            prm8.Value = emp.Bsc

I've used the money datatype itself even in the stored procedure variable.

I get the following error.
failed to convert parameter value from sql decimal to decimal
Even if i use

prm8.Value = Convert.ToDecimal(emp.Bsc)

I get an error
Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible'.

Please help me with the same. The code contains many files and is too long. As a result i've not pasted it here. Please do let me know if it is needed.

Thanks

Recommended Answers

All 3 Replies

In db also Make the column salray as decimal and try

In db also Make the column salray as decimal and try

I would lose a lot of data in the table that has been inserted already.

Coz ur having column of type money in DB and from front end your sending the decimal, try creating temtables and move the data and changecolumn type and import ur data from temp table

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.