SqlDataReader是否将所有内容存储为String?

spe*_*wah 1 c# sql

我正在尝试使用SqlDataReader来提取数据,其中一列是在datetime中.我想做这样的事情

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);
        }
    }
Run Code Online (Sandbox Code Playgroud)

我可以这样做吗?或者SqlDataReader是否返回字符串,在这种情况下,我必须使用该字符串创建一个新的DateTime对象?

谢谢,-S

Joe*_*ari 7

SqlDataReader将数据作为强类型对象返回 - 只需调用正确的方法,例如:

data.GetDateTime(序)