Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Attempting to save transaction details by query . at the press of the save button i get this error msg...."Implicit conversion from data type datetime to decimal is not allowed. Use the CONVERT function to run this query".

i checked the values for errors such as a unsuitable datatype, but they all were saved to the datetime datatype accordingly. checked the database that too was in the datetime datatype.

What could the problem be for this error?

What I have tried:

code in getter setter class;
public DateTime transaction_date { get; set; }

code in saving the value for variable, transaction_ date;
transaction.transaction_date = DateTime.Now;


The Query to insert value into database.
string sql = "INSERT INTO [transaction] (Dea_Cust_id, Grandtotal,transaction_date,  tax, discount) VALUES (@Dea_Cust_id,@transaction_date, @Grandtotal, @tax, @discount); SELECT @@IDENTITY;";

cmd.Parameters.AddWithValue("@transaction_date", transaction.transaction_date);
Posted
Updated 5-Aug-20 18:44pm
v2

1 solution

Isnt the order of these wrong ?
string sql = "INSERT INTO [transaction] (Dea_Cust_id, Grandtotal,transaction_date,  tax, discount) VALUES (@Dea_Cust_id,@transaction_date, @Grandtotal, @tax, @discount);
... should it not be
string sql = "INSERT INTO [transaction] (Dea_Cust_id, Grandtotal,transaction_date,  tax, discount) VALUES (@Dea_Cust_id,@Grandtotal, @transaction_date, @tax, @discount);
 
Share this answer
 
Comments
achalake 6-Aug-20 0:59am    
OMG, cant believe i didnt see that. this is embarassing. thank you soo much for your help!
Garth J Lancaster 6-Aug-20 2:04am    
meh - give yourself a break - sometimes we're so stressed/tired/etc etc we fail to see what's under our noses

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900