【问题标题】:System.InvalidOperationException:System.InvalidOperationException:
【发布时间】:2015-04-23 01:05:12
【问题描述】:
    protected void btnLogIn_Click(object sender, EventArgs e)
    {
        string ID = Request.Form["txtID"];
        String password = Request.Form["txtPassword"];
        string strConString = ConfigurationManager.ConnectionStrings["SOConnectionString"].ConnectionString;
        OleDbConnection conn = new OleDbConnection(strConString);
        OleDbCommand cmd = new OleDbCommand("SELECT * FROM USERMASTER WHERE USERID =" + ID + "");

        try
        {

           // ClientScript.RegisterStartupScript(this.GetType(), "yourMessage", "alert('" + ID + " " + password + "');", true);
            conn.Open();
            OleDbDataReader dr;

            dr = cmd.ExecuteReader();
            txtID.Text = "test1";
            //txtPassword.Text = dr["UserPwd"].ToString();
            //OleDbDataReader dr;
            //while (dr.Read()){
            //    ClientScript.RegisterStartupScript(this.GetType(), "yourMessage", "alert('" + ID + " " + password + "');", true);
            //    txtPassword.Text = dr["UserPwd"].ToString();
            //}

        }
        catch (Exception ex)
        {
            txtID.Text = "ex";
            lbltest.Text = ex.ToString();


        }
        finally
        {
            conn.Close();
            conn.Dispose();
        }

例外:

System.InvalidOperationException:ExecuteReader:连接属性尚未初始化。在 System.Data.OleDb.OleDbCommand.ValidateConnection(字符串方法) 在 System.Data.OleDb.OleDbCommand.ValidateConnectionAndTransaction(字符串方法) 在 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior 行为,字符串方法) 在 System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.OleDb.OleDbCommand.ExecuteReader() at _Default.btnLogIn_Click(Object sender, EventArgs e) in c:\Users\b2patso\Desktop\SO Maintainance\Default .aspx.cs:第 29 行

有谁知道这是怎么回事?我正在使用 asp.net C# 和 Visual Studio 2013。db 是 oracle

【问题讨论】:

  • 你把conn传给cmd了吗?
  • 字符串 strConString = ConfigurationManager.ConnectionStrings["SOConnectionString"].ConnectionString; OleDbConnection 连接 = 新 OleDbConnection(strConString); OleDbCommand cmd = new OleDbCommand("SELECT * FROM USERMASTER");字符串 ID = Request.Form["txtID"];字符串密码 = Request.Form["txtPassword"];
  • 尝试 OleDbCommand cmd = new OleDbCommand("SELECT * FROM USERMASTER", conn);
  • 它的工作......但是我怎么知道数据库中的数据已经传递出去了???是否使用 while(Read())?
  • 是的,while(read()) 应该做的工作

标签: c# asp.net database oracle


【解决方案1】:

尝试 OleDbCommand cmd = new OleDbCommand("SELECT * FROM USERMASTER", conn);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-02
    • 2012-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多