TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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
'
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) "
;
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.AddWithValue(
"@image"
, filename);
cmd.Parameters.AddWithValue(
"@name"
,txtname);
cmd.Parameters.AddWithValue(
"@label"
, txtlabelname);
cmd.Parameters.AddWithValue(
"@erx_required"
,
true
);
cmd.Parameters.AddWithValue(
"@quantity"
, txtquantity);
cmd.Parameters.AddWithValue(
"@price"
, txtprice);
cmd.Parameters.AddWithValue(
"@dosage"
, txtdosage);
cmd.Parameters.AddWithValue(
"@ndc"
, txtndc);
cmd.Parameters.AddWithValue(
"@tier_one"
, txttierone);
cmd.Parameters.AddWithValue(
"@tier_two"
, txttiertwo);
cmd.Parameters.AddWithValue(
"@tier_three"
, txttierthree);
cmd.Parameters.AddWithValue(
"@tier_four"
, txttierfour);
cmd.Parameters.AddWithValue(
"@tier_five"
, txttierfive);
cmd.Parameters.AddWithValue(
"@drug_form_id"
, ddldrugform);
cmd.Parameters.AddWithValue(
"@drug_category_id"
, ddldrugcategory);
cmd.Parameters.AddWithValue(
"@drug_class_id"
, ddldrugclass);
cmd.Parameters.AddWithValue(
"@drug_type_id"
, ddldrugtype);
cmd.Parameters.AddWithValue(
"@age_group_id"
, ddlagegroup);
cmd.Parameters.AddWithValue(
"@min_quantity"
, txtminquantity);
cmd.Parameters.AddWithValue(
"@max_quantity"
, txtmaxquantity);
cmd.Parameters.AddWithValue(
"@refillable"
,
true
);
cmd.Parameters.AddWithValue(
"@refill_limit"
, txtrefills);
cmd.Parameters.AddWithValue(
"@created_at"
,
Convert
.ToDateTime( DateTime.Now));
cmd.Parameters.AddWithValue(
"@updated_at"
,
Convert
.ToDateTime(DateTime.Now));
cmd.Parameters.AddWithValue(
"@description"
, string.Empty);
cmd.Parameters.AddWithValue(
"@contradiction"
, string.Empty);
cmd.Parameters.AddWithValue(
"@administration"
, string.Empty);
cmd.Parameters.AddWithValue(
"@missed_dose"
, string.Empty);
cmd.Parameters.AddWithValue(
"@interaction"
, string.Empty);
cmd.Parameters.AddWithValue(
"@monitoring"
, string.Empty);
cmd.Parameters.AddWithValue(
"@side_effects"
, string.Empty);
cmd.Parameters.AddWithValue(
"@storage"
, string.Empty);
cmd.Parameters.AddWithValue(
"@counselling"
, string.Empty);
cmd.Parameters.AddWithValue(
"@brand"
,
true
);
cmd.Parameters.AddWithValue(
"@active"
,
true
);
cmd.Parameters.AddWithValue(
"@qty_allowed"
,
true
);
con.
Open
();
cmd.ExecuteScalar();
con.
Close
();
SO what am I doing wrong here ?
Here , created_at & updated_at columns is of datatype Datetime in Sql table
Reply
Answers (
4
)
List.add replacing the all old values with new value
Passing Token to other API