HI
datetime _dt;
string ConnectionStr = ConfigurationManager.ConnectionStrings["cnn"].ConnectionString;
MySqlDataAdapter da = new MySqlDataAdapter("select curdate(),curtime()", ConnectionStr);
DataTable dt = new DataTable();
da.Fill(dt);
_dt = (DateTime)dt.Rows[0][0];
label5.Text = _dt.ToString("dd/MM/yyyy");
_dt = (DateTime)dt.Rows[0][1]; (Error : specified cast is not valid)
Thanks
Loading
mangesh shelarPosted Sep 7, 2011, 11:38 AM
string ConnectionStr = ConfigurationManager.ConnectionStrings["cnn"].ConnectionString;
MySqlDataAdapter da = new MySqlDataAdapter("SELECT NOW()", ConnectionStr);
DataTable dt = new DataTable();
da.Fill(dt);
DateTime DateVal = DateTime.Parse(dt.Rows[0][0].ToString());
lbFullDate.Text = DateVal.ToString();
lbDatePart.Text = DateVal.ToString("dd/MM/yyyy");
lbTimePart.Text = DateVal.ToString("HH:mm:ss");
Jaish MathewsPosted Sep 5, 2011, 4:06 AM
Use Convert.ToDateTime(). It wil work if the specified cell contains a valid value in date format.
_dt = Convert.ToDateTime(dt.Rows[0][1]);
Jagjit SainiPosted Sep 5, 2011, 3:50 AM
Then how can i get .
I want server date & Time separately . If time is 1:10 P.M (India) , i want time as 13:10.
Thanks
Jiteendra SampathiraoPosted Sep 5, 2011, 3:38 AM
it will added to _dt = (DateTime)dt.Rows[0][0];
but not to _dt = (DateTime)dt.Rows[0][1];// you cannot use this line of code...
Jagjit SainiPosted Sep 5, 2011, 3:30 AM
Error is in this line
_dt = (DateTime)dt.Rows[0][1]; (Error : specified cast is not valid)
Thanks
Jiteendra SampathiraoPosted Sep 5, 2011, 3:18 AM
I think in this line problem is occurring...label5.Text = _dt.ToString("dd/MM/yyyy");
(type casting)
trace every line by using breakpoint...you will come to know where the exact problem is occurs...