简体   繁体   English

SelectCommand.Connection属性尚未初始化

[英]SelectCommand.Connection property has not been initialized

Alright, I'm having an issue with logic flow. 好吧,我遇到了逻辑流程的问题。 For some reason one of the variables I'm declaring does not end up as existing in the current context. 由于某种原因,我声明的变量之一并不会最终存在于当前上下文中。 The error is on line 18: 错误在第18行:

Exception Details: System.InvalidOperationException: Fill: SelectCommand.Connection property has not been initialized.

Source Error: 


Line 16:            myAdapter.Fill(tabledata);
Line 17:        } catch (Exception ex) {
Line 18:            throw (ex);
Line 19:        } finally {
Line 20:            con.Close();

Here's the full page source: 这是完整的页面来源:

<% @Page Language="C#" Debug="true" %>
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.Odbc" %>
<% @Import Namespace="System.Web.Configuration" %>
<!-- #include file="header.html" -->
<%
    string conString = WebConfigurationManager.ConnectionStrings["stampConnectionString"].ConnectionString;
    OdbcDataAdapter myAdapter = new OdbcDataAdapter();  
    DataTable tabledata = new DataTable();      
    using (OdbcConnection con = new OdbcConnection(conString)) {
        using (OdbcCommand com = new OdbcCommand("SELECT * FROM cheeseisdelicious", con)) {
            myAdapter.SelectCommand = com;
        }
        try {
            con.Open();
            myAdapter.Fill(tabledata);
        } catch (Exception ex) {
            throw (ex);
        } finally {
            con.Close();
        }
    }
    Response.Write("<table>");
    foreach (DataRow row in tabledata.Rows) {
        Response.Write("<tr>");
        foreach (var item in row.ItemArray) {
            Response.Write("<td>" + item + "</td>");
        }
        Response.Write("</tr>");
    }
    Response.Write("</table>");

%>
<!-- #include file="footer.html" -->

Take a look at your brackets around usings . 看看周围的括号usings The inner one, just after 内在的,就在之后

    myAdapter.SelectCommand = com;
} <- this one!

disposes your command. 处理你的命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 填充:SelectCommand.Connection属性尚未初始化错误 - Fill: SelectCommand.Connection property has not been initialized error 填充:SelectCommand.Connection属性尚未初始化 - Fill: SelectCommand.Connection property has not been initialized 错误填充:SelectCommand.Connection属性尚未初始化 - error Fill: SelectCommand.Connection property has not been initialized 如何解决Fill:SelectCommand.Connection属性尚未初始化 - how to solve Fill: SelectCommand.Connection property has not been initialized 填充:SelectCommand.Connection 属性尚未初始化 C# - Fill: SelectCommand.Connection property has not been initialized C# SelectCommand.Connection属性尚未初始化。 MySQL的 - The SelectCommand.Connection property has not been initialized. MySql 填充:SelectCommand.Connection 属性尚未初始化 - Fill: SelectCommand.Connection property has not been initialized C#错误:“填充:SelectCommand.Connection属性尚未初始化。” - C# Error: “Fill: SelectCommand.Connection property has not been initialized.” 填充:SelectCommand.Connection属性尚未初始化。 该怎么办? - Fill: SelectCommand.Connection property has not been initialized. what to do? C#错误:“填充:SelectCommand.Connection属性尚未初始化。” - C# Error: “Fill: SelectCommand.Connection property has not been initialized.”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM