I am developing an app in VS2010 c# to fetch a single row data from SQLServer and insert it to MySQL.
I have fetched data and stored in particular string variable. Fetching code is as below.
SqlCommand cmd = new SqlCommand("SELECT TOP (1) s_name, s_city, s_address, s_added_date, s_added_by FROM tblAQI ORDER BY s_added_date DESC", SSCon);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
s_name = (dr["s_name"].ToString());
s_city = (dr["s_city"].ToString());
s_address = (dr["s_address"].ToString());
s_added_date = (dr["s_added_date"].ToString());
s_added_by = (dr["s_added_by"].ToString());
}
dr.Close();
Now I have all the values but to insert datetime in MySQL need to format string in yyyy-mm-dd hh:mm:ss format. To fulfil this I have code below
s_added_date = s_added_date.Substring(0, s_added_date.Length - 3);
DateTime datevalue = DateTime.Parse(s_added_date);
string formatForMySql = datevalue.ToString("yyyy-MM-DD HH:MM:SS");
When I get the output I am getting 2013-11-DD 12:11:SS Not getting what's wrong here.
Please help to resolve it.
Thanks in advance.