我使用以下代码从表中检索列
SqlCommand cmd1 = new SqlCommand();
SqlDataReader reader1 = null;
cmd1.CommandType = CommandType.Text;
cmd1.Connection = conn;
cmd1.CommandText = "......";
reader1 = cmd1.ExecuteReader();
while (reader1.Read())
{
Label32.Text = (reader["Unit"]).ToString();
}
连接已打开。我的问题是从表中检索空值时,列中有很多空值。它会给予我错误“当读取器关闭时,调用元数据的尝试无效”。我该如何解决这个问题。谢谢。
对“Label32.Text =(reader[“Unit”]).ToString()“时引发了异常;“
堆栈追踪:
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlDataReader.CheckMetaDataIsReady()
at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)
at System.Data.SqlClient.SqlDataReader.get_Item(String name)
at TSOD._1Test.Page_Load(Object sender, EventArgs e) in h:\TSODNEW\TSOD\1Test.aspx.cs:line 75
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
1条答案
按热度按时间oxcyiej71#
试试看: