I'm trying for two days to add date in my database table but every time I see this 12:00:00 AM value instead of actual time. I tried enough for this simple issue.
http://puu.sh/cpP2l/0b0dd66042.png
obj.Payment_date = DateTime.Now.ToString("G");
using (SqlCommand command = new SqlCommand("INSERT into Payments([software_id] ,[email] ,[ip] ,[payment_status] ,[payment_date] ,[transaction_id] ,[amount] ,[license_type] ,[license_status] ,[cd_key]) VALUES(@software_id ,@email ,@ip ,@payment_status ,@payment_date ,@transaction_id ,@amount ,@license_type ,@license_status ,@cd_key)", con))
{
command.Parameters.Add(new SqlParameter("software_id", obj.Software_id));
command.Parameters.Add(new SqlParameter("email", obj.Email));
command.Parameters.Add(new SqlParameter("ip", obj.IP));
command.Parameters.Add(new SqlParameter("payment_status",obj.Payment_status));
command.Parameters.Add(new SqlParameter("payment_date", obj.Payment_date));
command.Parameters.Add(new SqlParameter("transaction_id", obj.Transaction_id));
command.Parameters.Add(new SqlParameter("amount", obj.Amount));
command.Parameters.Add(new SqlParameter("license_type", obj.License_type));
command.Parameters.Add(new SqlParameter("license_status",obj.License_status));
command.Parameters.Add(new SqlParameter("cd_key", obj.Cd_key));
if (command.ExecuteNonQuery() > 0)
{
}
}
payment_datecolumn must be of typeDATETIMEin the database. Theobj.Payment_dateshould be aDateTimetype, not a string.