[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Teodorico Morell

9/25/2002 7:50:00 PM

I'm inserting rows in a MS Access database into the following table using
parameters:

CREATE TABLE MODEL (
F_MODEL_ID LONG NOT NULL,
F_MODEL MEMO NOT NULL,
CONSTRAINT PK_MODEL
PRIMARY KEY (F_MODEL_ID)
);

I can only insert into "F_MODEL" strings with a length between 1-255 or 2000
and up.
Any string with a length between 256 and 1999 throws the following error:

"ERROR [HY104] [Microsoft][ODBC Microsoft Access Driver]Invalid precision
value"

It seems that the ODBC layer is assigning the wrong data type for any length
between 256 and 1999!

The code is:
============================================================
IDbDataParameter model = com.CreateParameter();
model.DbType = DbType.String;
model.Direction = ParameterDirection.Input;
model.ParameterName = "model";

string s = "";
for (int i = 1; i <= 2000; i++) // 1-255 and 2000 and up works fine
s += "A";
model.Size = s.Length;
model.Value = s;

com.Parameters.Add(model);
com.CommandType = System.Data.CommandType.Text;

sql = "INSERT INTO bs_model (f_model_id, f_model) VALUES (" +
this.ID.ToString() + ", ?)";
com.CommandText = sql;

com.ExecuteNonQuery(); // <<< ---- Error in this line

com.Parameters.Clear();
============================================================


Is there a better way to insert memo fiels?

Thanks.



2 Answers

laled

9/28/2002 1:54:00 AM

0

You can help odbc.net choose the right type by setting the
OdbcType property of the OdbcParameter class yourself, ie:
model.OdbcType = OdbcType.NText;

Then everything should work correctly.
Thanks
Laled

This posting is provided "AS IS" with no warranties, and
confers no rights.

>-----Original Message-----
>I'm inserting rows in a MS Access database into the
following table using
>parameters:
>
>CREATE TABLE MODEL (
> F_MODEL_ID LONG NOT NULL,
> F_MODEL MEMO NOT NULL,
> CONSTRAINT PK_MODEL
> PRIMARY KEY (F_MODEL_ID)
>);
>
>I can only insert into "F_MODEL" strings with a length
between 1-255 or 2000
>and up.
>Any string with a length between 256 and 1999 throws the
following error:
>
>"ERROR [HY104] [Microsoft][ODBC Microsoft Access Driver]
Invalid precision
>value"
>
>It seems that the ODBC layer is assigning the wrong data
type for any length
>between 256 and 1999!
>
>The code is:
>==========================================================
==
>IDbDataParameter model = com.CreateParameter();
>model.DbType = DbType.String;
>model.Direction = ParameterDirection.Input;
>model.ParameterName = "model";
>
>string s = "";
>for (int i = 1; i <= 2000; i++) // 1-255 and 2000 and
up works fine
> s += "A";
>model.Size = s.Length;
>model.Value = s;
>
>com.Parameters.Add(model);
>com.CommandType = System.Data.CommandType.Text;
>
>sql = "INSERT INTO bs_model (f_model_id, f_model) VALUES
(" +
>this.ID.ToString() + ", ?)";
>com.CommandText = sql;
>
>com.ExecuteNonQuery(); // <<< ---- Error in this
line
>
>com.Parameters.Clear();
>==========================================================
==
>
>
>Is there a better way to insert memo fiels?
>
>Thanks.
>
>
>
>.
>

Teodorico Morell

9/28/2002 5:27:00 PM

0

Thanks for the reply. It worked.

As I work with ODBC or OLEDB, I place the following code:

Microsoft.Data.Odbc.OdbcParameter p = model as
Microsoft.Data.Odbc.OdbcParameter;
if (p != null)
p.OdbcType = Microsoft.Data.Odbc.OdbcType.NText;


Laled, do you have any idea when there is going to be a release fixing the
bugs reported in this newsgroup?

Thanks.


Teo