Guest User

Guest User

  • Tech Writer
  • 515
  • 47.1k

About ADO.Net in MVC

Feb 9 2021 11:06 PM
hello, hope everyone is fine
 
I am saving some data to sql database using ado.net
Following is the code, but getting error of -  'Implicit conversion from data type datetime to bit is not allowed. Use the CONVERT function to run this query'
  1. string query = "INSERT INTO drug_details VALUES(@image,@name, @label, @erx_required,@quantity, @price, @dosage,@ndc, @tier_one, @tier_two, @tier_three, @tier_four, @tier_five,@drug_form_id, @drug_category_id, @drug_class_id,@drug_type_id, @age_group_id, @min_quantity,@max_quantity, @refillable, @refill_limit,@created_at, @updated_at,@description,@contradiction,@administration,@missed_dose,@interaction,@monitoring,@side_effects,@storage,@counselling,@brand,@active,@qty_allowed) ";  
  2. SqlCommand cmd = new SqlCommand(query, con);  
  3. cmd.Parameters.AddWithValue("@image", filename);  
  4. cmd.Parameters.AddWithValue("@name",txtname);  
  5. cmd.Parameters.AddWithValue("@label", txtlabelname);  
  6. cmd.Parameters.AddWithValue("@erx_required",true);  
  7. cmd.Parameters.AddWithValue("@quantity", txtquantity);  
  8. cmd.Parameters.AddWithValue("@price", txtprice);  
  9. cmd.Parameters.AddWithValue("@dosage", txtdosage);  
  10. cmd.Parameters.AddWithValue("@ndc", txtndc);  
  11. cmd.Parameters.AddWithValue("@tier_one", txttierone);  
  12. cmd.Parameters.AddWithValue("@tier_two", txttiertwo);  
  13. cmd.Parameters.AddWithValue("@tier_three", txttierthree);  
  14. cmd.Parameters.AddWithValue("@tier_four", txttierfour);  
  15. cmd.Parameters.AddWithValue("@tier_five", txttierfive);  
  16. cmd.Parameters.AddWithValue("@drug_form_id", ddldrugform);  
  17. cmd.Parameters.AddWithValue("@drug_category_id", ddldrugcategory);  
  18. cmd.Parameters.AddWithValue("@drug_class_id", ddldrugclass);  
  19. cmd.Parameters.AddWithValue("@drug_type_id", ddldrugtype);  
  20. cmd.Parameters.AddWithValue("@age_group_id", ddlagegroup);  
  21. cmd.Parameters.AddWithValue("@min_quantity", txtminquantity);  
  22. cmd.Parameters.AddWithValue("@max_quantity", txtmaxquantity);  
  23. cmd.Parameters.AddWithValue("@refillable"true);  
  24. cmd.Parameters.AddWithValue("@refill_limit", txtrefills);  
  25. cmd.Parameters.AddWithValue("@created_at"Convert.ToDateTime( DateTime.Now));  
  26. cmd.Parameters.AddWithValue("@updated_at"Convert.ToDateTime(DateTime.Now));  
  27. cmd.Parameters.AddWithValue("@description", string.Empty);  
  28. cmd.Parameters.AddWithValue("@contradiction", string.Empty);  
  29. cmd.Parameters.AddWithValue("@administration", string.Empty);  
  30. cmd.Parameters.AddWithValue("@missed_dose", string.Empty);  
  31. cmd.Parameters.AddWithValue("@interaction", string.Empty);  
  32. cmd.Parameters.AddWithValue("@monitoring", string.Empty);  
  33. cmd.Parameters.AddWithValue("@side_effects", string.Empty);  
  34. cmd.Parameters.AddWithValue("@storage", string.Empty);  
  35. cmd.Parameters.AddWithValue("@counselling", string.Empty);  
  36. cmd.Parameters.AddWithValue("@brand"true);  
  37. cmd.Parameters.AddWithValue("@active"true);  
  38. cmd.Parameters.AddWithValue("@qty_allowed"true);  
  39. con.Open();  
  40. cmd.ExecuteScalar();  
  41. con.Close(); 
SO what am I doing wrong here ?
Here , created_at & updated_at  columns is of datatype Datetime in Sql table

Answers (4)