我想提取DATE和TIME为两个不同的变量,可以用来显示在文本框中。如何从C#中的结果MySQL查询中提取特定的DATE和TIME?
以下是我在我的代码正在做的 -
MySqlCommand cmd3 = new MySqlCommand();
MySqlDataReader reader2 = null;
cmd3.CommandText = "SELECT lastlogintime from authentication where [email protected]";
cmd3.Parameters.AddWithValue("@email", LoggedInUser);
cmd3.Connection = connect;
reader2 = cmd3.ExecuteReader();
while (reader2.Read())
{
string temp = reader2.GetString(reader2.GetOrdinal("lastlogintime"));
lastloginDateTB.Text = temp.ToString(); // This will give full string as (yyyymmdd HH:mm:ss) into lastloginDateTb
// Now I want to display date in Date_TB and Time in Time_TB. Note: I have 2 different textboxes as lastloginDateTB & lastloginTimeTB ;
}
从认证表(lastlogintime列)此代码提取值到临时变量,并显示在lastloginDateTB文本相同的,但我想在每个列中显示特定的日期和时间。
注:表由字段名的 - lastlogintime具有DATETIME值。
你为什么不使用'SqlDateTime'?然后你将它转换为'DateTime'获取'Date'组件和'time' – MotKohn