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

Jiteendra SampathiraoRank #585 · 4.1K reputationPosted Sep 4, 2011, 11:18 PM EDT
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...
Jagjit Saini166 reputationPosted Sep 4, 2011, 11:30 PM EDT
Error is in this line
_dt = (DateTime)dt.Rows[0][1]; (Error : specified cast is not valid)
Thanks
Jiteendra SampathiraoRank #585 · 4.1K reputationPosted Sep 4, 2011, 11:38 PM EDT
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 Saini166 reputationPosted Sep 4, 2011, 11:50 PM EDT
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
Jaish MathewsRank #225 · 11K reputationPosted Sep 5, 2011, 12:06 AM EDT
Use Convert.ToDateTime(). It wil work if the specified cell contains a valid value in date format.
_dt = Convert.ToDateTime(dt.Rows[0][1]);
mangesh shelar13 reputationPosted Sep 7, 2011, 7:38 AM EDT
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");