我正在尝试使用 SqlDataReader 提取数据,其中一列是日期时间。我想做这样的事情
SqlCommand command = new SqlCommand("SELECT * FROM table", connection); //connection is defined earlier
SqlDataReader data = command.ExecuteReader();
while(data.Read()){
DateTime birthday = data["Birth"];
list.Add(birthday);
}
}
我可以这样做吗?或者 SqlDataReader 是否返回字符串,在这种情况下我必须使用该字符串创建一个新的 DateTime 对象?
谢谢, -S
最佳答案
SqlDataReader 将数据作为强类型对象返回 - 只需调用正确的方法,例如:
data.GetDateTime(顺序)
关于c# - SqlDataReader 是否将所有内容存储为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/855676/