I'm trying to update the date in database which at the begining is set to null, and the datatype used for date are nvarchar(50).
I've even tried nchar, date, varchar(50) datatypes in SQL Server but when updating it gives me error saying:
Conversion failed when converting date and/or time from character string.
How do I get rid of this and I want to disaply date in format 2-feb-2013 using
dd.tostring("D);
and it is not working.
SqlCommand cmd = new SqlCommand("update barcode set intime=@time,date='@date' where bcd=@bcd", con);
cmd.Parameters.Add("@cc", SqlDbType.NChar, 20).Value = c;
cmd.Parameters.Add("@bcd", SqlDbType.NChar, 20, "bcd").Value = textBox1.Text;
DateTime dd = DateTime.Now;
String ss, sss;
ss = dd.ToString("t");
sss = dd.ToString("d");
cmd.Parameters.Add("@time", SqlDbType.NVarChar, 50, "intime").Value = ss;
cmd.Parameters.Add("@date", SqlDbType.Date, 50, "date").Value = sss;
cmd.ExecuteNonQuery();