C # operation Access, there are "Internal error: Invalid parameter accessor: 2 Badbindinfo" solution __c#

Source: Internet
Author: User

Common Code Snippets for C # operations SQL databases are as follows:

<summary>
    ///Execute command
    ///</summary>
    ///<param name= "procname" > Command text </param>
    ///<param name= "prams" > Parameter object </param>
    ///<returns></returns> public
    int Runproc (String procname, sqlparameter[] prams)
    {
        SqlCommand cmd = CreateCommand (procname, prams);
        Cmd. ExecuteNonQuery ();
        This. Close ();
        Get execution Success return value
        (int) cmd. parameters["ReturnValue"]. Value;
    }
///<summary>///Create a SqlCommand object to execute command text///</summary>///<param name= "ProcName" > Command text </param>///<param name= "prams" command text required parameters </param>///<returns> return SqlCommand pair
        Like </returns> private SqlCommand CreateCommand (String procname, sqlparameter[] prams) {//Confirm open connection This.
        Open ();
        SqlCommand cmd = new SqlCommand (procname, con);     Cmd.commandtype = CommandType.Text; Execution Type: Command text//In turn, parameters are passed in the command text if (prams!= null) {foreach (SqlParameter parameter in PR AMS) cmd.
        Parameters.Add (parameter); //Join return parameter cmd. Parameters.Add (New SqlParameter ("ReturnValue", SqlDbType.Int, 4, ParameterDirection.ReturnValue, False, 0, 0, string.

        Empty, Datarowversion.default, null));
    return cmd; }

If you change SQL into Access. The appropriate code simply needs to replace the SQL type with an OLE DB type.

The common code for C # to manipulate an Access database is as follows:

<summary>
        ///Execute command
        ///</summary>
        ///<param name= "procname" > Command text </param>
        ///<param name= "prams" > Parameter object </param>
        ///<returns></returns> public
        int Runproc (String procname, oledbparameter[] prams)
        {
            OleDbCommand cmd = CreateCommand (procname, prams);
            Cmd. ExecuteNonQuery ();
            This. Close ();
            Get executed successfully return value
            //return (int) cmd. parameters["ReturnValue"]. Value;
            return 1;
        }
<summary>///Create a OleDbCommand object to execute the command text///</summary>///<param name= "proc Name ' > Command text </param>///<param name= ' prams ' command text required parameters </param>///<returns> return oledbcom
            Mand Objects </returns> Private OleDbCommand CreateCommand (String procname, oledbparameter[] prams) { Confirm open Connection this.
            Open ();
            OleDbCommand cmd = new OleDbCommand (procname, con);     Cmd.commandtype = CommandType.Text; Execution Type: Command text//In turn, the arguments are passed in the command text if (prams!= null) {foreach (Oledbparamet ER parameter in prams) cmd.
            Parameters.Add (parameter); //Join return parameter//cmd. Parameters.Add (//New OleDbParameter ("ReturnValue", OleDbType.Integer, 4,//Parameterdirec tion. ReturnValue, False, 0, 0,//String.
         Empty, Datarowversion.default, null));   return cmd; }

Because Access does not need to return a value. So the CreateCommand function does not need the following parts:

Cmd. Parameters.Add (
            new SqlParameter ("ReturnValue", SqlDbType.Int, 4,
            ParameterDirection.ReturnValue, False, 0, 0,
            string. Empty, Datarowversion.default, null));

If this part is not removed, the code that operates the SQL is still copied. There will be an error "Exception details: System.InvalidOperationException:System.Data.OleDb.OleDbDataAdapter INTERNAL error: Invalid parameter accessor: 2 badbindinfo. ”

If you encounter a similar error, you may wish to comment out the return value as described above.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.