System.InvalidOperationException:

时间:2015-04-23 01:05:12

标签: c# asp.net database oracle

    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:尚未初始化Connection属性。处于System.Data.OleDb.OleDb.OleDb.OleDb.mand上的System.Data.OleDb.OleDbCommand.ValidateConnection(String方法)System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior,String method)中的System.Data.OleDb.OleDbCommand.ValidateConnection(String方法)   位于System.Data.OleDb.OleDbCommand.ExecuteReader()的System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)位于_Default.btnLogIn_Click(Object sender,EventArgs e)的c:\ Users \ b2patso \ Desktop \ SO Maintainance \ Default .aspx.cs:第29行

任何人都知道这是什么问题?我正在使用asp.net C#和visual studio 2013.db是oracle

1 个答案:

答案 0 :(得分:0)

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