Hi everyone,
I am getting weird behavior, I am trying to insert into an MS Access
using SQL with parameter - so far so good.
I noticed that when I am using an open cursor .AddNew it works just
fine, but when I try to use a command it fails with
"Application uses a value of the wrong type for the current
operation."
What I've noticed, is that while the type of the field comes the right
way (i.e. DataTypeEnum.adLongVarWChar) the actual type the parameter
gets is wrong (DataTypeEnum.adVarWChar) trying to set it throws
Error: Missing method 'instance void [db]
ADODB._Parameter::set_Type(valuetype ADODB.DataTypeEnum)' from class
'ADODB.InternalParameter'.
oh come on ... "missing method" ? what am I supposed to do with that ?
[code]
//**** the following works *****/
static void useRs(Connection cn)
{
int len = 60011;
Recordset rs = new ADODB.Recordset();
String SQL = "SELECT * FROM animals";
rs.Open(SQL, cn, CursorTypeEnum.adOpenKeyset,
LockTypeEnum.adLockOptimistic);
rs.AddNew();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i++) sb.Append(i % 10);
String sData = sb.ToString();
int charsDone = 0;
int chars2Read;
while (sData.Length != charsDone)
{
chars2Read = Math.Min(BLOCK_SIZE, sData.Length -
charsDone);
rs.Fields["sMemo"].AppendChunk(sData.Substring(charsDone,
chars2Read));
charsDone += chars2Read;
}
rs.Update();
}
/**** fails ***/
static void useCmd(Connection con)
{
int len = 60011;
Command cmd = new Command();
cmd.ActiveConnection = con;
cmd.CommandText = "Insert into animals (sMemo) values
( @ppp)";
Parameter p = cmd.Parameters["@ppp"];
cmd.CreateParameter("@ppp",
ADODB.DataTypeEnum.adLongVarWChar,
ParameterDirectionEnum.adParamInput, len);
// here the type is DataTypeEnum.adVarWChar which is why
it fails (I guess)
//p.Type = DataTypeEnum.adLongVarWChar;
p = cmd.Parameters["@ppp"];
StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i++) sb.Append(i % 10);
String sData = sb.ToString();
int charsDone = 0;
int chars2Read;
while (sData.Length != charsDone)
{
chars2Read = Math.Min(BLOCK_SIZE, sData.Length -
charsDone);
p.AppendChunk(sData.Substring(charsDone, chars2Read));
charsDone += chars2Read;
}
object recAff;
cmd.Execute(out recAff);
}
[/code]
Thanks