By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,572 Members | 963 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,572 IT Pros & Developers. It's quick & easy.

ERROR: [ODBC Microsoft Access Driver]Invalid precision value

P: n/a
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[i]));
}
return;
}
----CODE END ----

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

Reza.
Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Thu, 8 Sep 2005 13:50:05 -0700, Reza Nabi <rn***@hotmail.com> 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[i]));
}
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)
Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.