【发布时间】:2019-05-26 21:59:10
【问题描述】:
我在 ASP.net 中创建了一个表,我想在页面加载后使用来自数据库的信息填充该表。我收到指定演员表无效的错误。我究竟做错了什么?这是我的代码
public string getData()
{
string htmlStr = "";
SqlConnection conn = new SqlConnection(connString);
SqlCommand command = conn.CreateCommand();
command.CommandText = "SELECT * from INFO";
conn.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
DateTime Date = reader.GetDateTime(0);
DateTime Time = reader.GetDateTime(1);
htmlStr += "<tr><td>" + Date + "</td><td>" + Time + "</td></tr>";
}
conn.Close();
return htmlStr;
}
<table style="width:100%">
<caption>INFO</caption>
<tr>
<td> Date </td>
<td> Time </td>
</tr>
<%=getData()%>
</table>
这是我的错误:
上面的代码在这一行抛出了异常:
DateTime Date = reader.GetDateTime(0);
【问题讨论】:
-
@Grant 这行
DateTime Date = reader.GetDateTime(0);抛出异常 -
好的,我现在可以超过日期,但现在抛出时间异常?
-
time(7) 是数据类型