Old ADO problem

  • Thread starter Thread starter Daniel
  • Start date Start date
D

Daniel

Hello,

i've created an old-ADO-recordset in C# via the following
code:

ADODB.RecordsetClass arTest;

arTest = new ADODB.RecordsetClass();

arTest.Fields.Append("Field1",
ADODB.DataTypeEnum.adInteger, -
1,ADODB.FieldAttributeEnum.adFldUnspecified,null);

arTest.Fields.Append("Field2",
ADODB.DataTypeEnum.adInteger, -
1,ADODB.FieldAttributeEnum.adFldUnspecified,null);

arTest.Open(null, null,
ADODB.CursorTypeEnum.adOpenForwardOnly,
ADODB.LockTypeEnum.adLockReadOnly,-1);

So far, so good, seems to work. Now i want to fill it with
data:
arTest.AddNew("Field1", 1);

And what i got is this:
Unhandled Exception:
System.Runtime.InteropServices.COMException (0x800A0BB9):
Arguments are of the wrong type, are out of acceptable
range, or are in conflict with one another.

Any ideas, how i can handle this?

Thanks in advance,
Daniel
 
Hi Daniel,

I should have caught this in my previous post. You need to change your call
to the Open method a little further. Try:

using System.Reflection;
using ADODB;
...........
arTest.Open(Missing.Value, Missing.Value, CursorTypeEnum.adOpenStatic,
LockTypeEnum.adLockOptimistic,-1);


Full sample code for a console app follows:

using System;
using System.Reflection;
using ADODB;

namespace ConsoleApplication3
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
ADODB.RecordsetClass arTest;

try
{
arTest = new ADODB.RecordsetClass();

arTest.Fields.Append("Field1",
ADODB.DataTypeEnum.adInteger, -
1,ADODB.FieldAttributeEnum.adFldUnspecified,null);

arTest.Fields.Append("Field2",
ADODB.DataTypeEnum.adInteger, -
1,ADODB.FieldAttributeEnum.adFldUnspecified,null);

arTest.Open(Missing.Value, Missing.Value,
ADODB.CursorTypeEnum.adOpenStatic,
ADODB.LockTypeEnum.adLockOptimistic,-1);

arTest.AddNew("Field1", 10);

System.Console.WriteLine("Field added. Value of first field
is {0}", arTest.Fields[0].Value.ToString());
}
catch (Exception ex)
{
System.Console.WriteLine(ex.Message);
}
finally
{
System.Console.ReadLine();
}
}
}
}
 
Well, this works. Many thanks!

Greetings,
Daniel
-----Original Message-----

Hi Daniel,

I should have caught this in my previous post. You need to change your call
to the Open method a little further. Try:

using System.Reflection;
using ADODB;
...........
arTest.Open(Missing.Value, Missing.Value, CursorTypeEnum.adOpenStatic,
LockTypeEnum.adLockOptimistic,-1);


Full sample code for a console app follows:

using System;
using System.Reflection;
using ADODB;

namespace ConsoleApplication3
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
ADODB.RecordsetClass arTest;

try
{
arTest = new ADODB.RecordsetClass();

arTest.Fields.Append("Field1",
ADODB.DataTypeEnum.adInteger, -
1,ADODB.FieldAttributeEnum.adFldUnspecified,null);

arTest.Fields.Append("Field2",
ADODB.DataTypeEnum.adInteger, -
1,ADODB.FieldAttributeEnum.adFldUnspecified,null);

arTest.Open(Missing.Value, Missing.Value,
ADODB.CursorTypeEnum.adOpenStatic,
ADODB.LockTypeEnum.adLockOptimistic,- 1);

arTest.AddNew("Field1", 10);

System.Console.WriteLine("Field added. Value of first field
is {0}", arTest.Fields[0].Value.ToString());
}
catch (Exception ex)
{
System.Console.WriteLine(ex.Message);
}
finally
{
System.Console.ReadLine();
}
}
}
}


--
Rob Windsor
G6 Consulting
Toronto, Canada



Daniel said:
Somebody send me a hint, that the recordset is opened as
read-only. I've changed it to:

arTest.Open(null, null,
ADODB.CursorTypeEnum.adOpenStatic,
ADODB.LockTypeEnum.adLockOptimistic,-1);

But the error still occures.


.
 
Back
Top