ERROR: [ODBC Microsoft Access Driver]Invalid precision value

Discussion in 'ASP .Net' started by =?Utf-8?B?UmV6YSBOYWJp?=, Sep 8, 2005.

  1. Dear All:
    I have been developing ASP.NET application on MS Access database using ODBC.
    When I was trying to save more than 255 chars in a Memo field I got the
    following error.
    ERROR [HY104] [Microsoft][ODBC Microsoft Access Driver]Invalid precision
    value

    Below is the code snippet of two function where it is breaking. Any advice
    on this would be greatly appreciated.

    ----CODE BEGIN---
    public static int ExecuteNonQuery(string connString, string cmdText, params
    object[] parameterValues)
    {
    OdbcConnection conn = new OdbcConnection(connString);
    conn.Open();
    OdbcCommand cmd = new OdbcCommand(cmdText, conn);
    if ((parameterValues != null) && (parameterValues.Length > 0))
    {
    AssignParameterValues(cmd, parameterValues);
    }
    // GOT THE FOLLOWING ERROR WHILE EXECUTING THE UPDATE QUERY WITH MORE THAN
    256 CHARS FOR MEMO FIELD
    // ERROR [HY104] [Microsoft][ODBC Microsoft Access Driver]Invalid precision
    value
    int nRowsAffected = Convert.ToInt32(cmd.ExecuteNonQuery());
    conn.Close();
    return nRowsAffected;

    }

    private static void AssignParameterValues(OdbcCommand cmd, object[]
    parameterValues)
    {
    if (parameterValues == null)
    {
    return;
    }
    for (int i = 0, j = parameterValues.Length; i < j; i++)
    {
    cmd.Parameters.Add(new OdbcParameter("@"+i,parameterValues));
    }
    return;
    }
    ----CODE END ----

    Thank you so much and looking forward to your kind response.

    Reza.
    =?Utf-8?B?UmV6YSBOYWJp?=, Sep 8, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?UmV6YSBOYWJp?=

    Paul Clement Guest

    On Thu, 8 Sep 2005 13:50:05 -0700, Reza Nabi <> wrote:

    ¤ Dear All:
    ¤ I have been developing ASP.NET application on MS Access database using ODBC.
    ¤ When I was trying to save more than 255 chars in a Memo field I got the
    ¤ following error.
    ¤ ERROR [HY104] [Microsoft][ODBC Microsoft Access Driver]Invalid precision
    ¤ value
    ¤
    ¤ Below is the code snippet of two function where it is breaking. Any advice
    ¤ on this would be greatly appreciated.
    ¤
    ¤ ----CODE BEGIN---
    ¤ public static int ExecuteNonQuery(string connString, string cmdText, params
    ¤ object[] parameterValues)
    ¤ {
    ¤ OdbcConnection conn = new OdbcConnection(connString);
    ¤ conn.Open();
    ¤ OdbcCommand cmd = new OdbcCommand(cmdText, conn);
    ¤ if ((parameterValues != null) && (parameterValues.Length > 0))
    ¤ {
    ¤ AssignParameterValues(cmd, parameterValues);
    ¤ }
    ¤ // GOT THE FOLLOWING ERROR WHILE EXECUTING THE UPDATE QUERY WITH MORE THAN
    ¤ 256 CHARS FOR MEMO FIELD
    ¤ // ERROR [HY104] [Microsoft][ODBC Microsoft Access Driver]Invalid precision
    ¤ value
    ¤ int nRowsAffected = Convert.ToInt32(cmd.ExecuteNonQuery());
    ¤ conn.Close();
    ¤ return nRowsAffected;
    ¤
    ¤ }
    ¤
    ¤ private static void AssignParameterValues(OdbcCommand cmd, object[]
    ¤ parameterValues)
    ¤ {
    ¤ if (parameterValues == null)
    ¤ {
    ¤ return;
    ¤ }
    ¤ for (int i = 0, j = parameterValues.Length; i < j; i++)
    ¤ {
    ¤ cmd.Parameters.Add(new OdbcParameter("@"+i,parameterValues));
    ¤ }
    ¤ return;
    ¤ }
    ¤ ----CODE END ----
    ¤

    I would highly recommend you use the Jet OLEDB provider and the .NET OLEDB namespace instead. The
    following works for me:

    Sub WriteMemoToAccess()

    Dim AccessConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=e:\My Documents\db1.mdb")
    Dim AccessCommand As New OleDbCommand("UPDATE Table1 SET MemoField=? WHERE [record id] = 1",
    AccessConnection)
    Dim StringValue As String = "Very long text...................."
    Dim QueryParameter As New OleDbParameter("@LongText", OleDbType.LongVarWChar,
    Len(StringValue), ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current,
    StringValue)
    AccessCommand.Parameters.Add(QueryParameter)
    AccessConnection.Open()
    AccessCommand.ExecuteNonQuery()
    AccessConnection.Close()

    End Sub


    Paul
    ~~~~
    Microsoft MVP (Visual Basic)
    Paul Clement, Sep 9, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page