我有一个包含日期时间字段的表,我想检索该日期并在c#上的日期时间选择器上显示它,我该如何实现?
reader = oleDbCmd.ExecuteReader();
reader.Read();
DTPicker.Value += reader[1];
reader.Close();
日期在我表的第二栏。
答案 0 :(得分:1)
以下是如何从OleDbDataReader读取数据的示例:
private static void ReadData(string connectionString)
{
string queryString = "SELECT OrderID, CustomerID FROM Orders";
using (OracleConnection connection = new OracleConnection(connectionString))
{
OracleCommand command = new OracleCommand(queryString, connection);
connection.Open();
OracleDataReader reader;
reader = command.ExecuteReader();
// Always call Read before accessing data.
while (reader.Read())
{
Console.WriteLine(reader.GetInt32(0) + ", " + reader.GetString(1));
}
// Always call Close when done reading.
reader.Close();
}
}
您可以使用reader.GetInt(0)
Convert.ToDateTime(reader[0])