Re: ADO 2.7 C# - How Do I Create a Recordset On-the-Fly?



Chris wrote on Mon, 6 Feb 2006 06:30:11 -0800:

I'm using ADO 2.7 for compatibility with an existing component I'm using.
I'm trying to add data to a recordset that I've created on-the-fly using
C# .NET 2003 (I'm new to C#, so please bear with me...). rs.Open requires
a Source and Active Connection parameter. Since the recordset is created
and populated from code, I'm not sure how to satisfy these two parameters.

In a nutshell, here's what I'm trying to do:

rs.Fields.Append("type", ADODB.DataTypeEnum.adVarChar, 1,
ADODB.FieldAttributeEnum.adFldMayBeNull, null);
rs.Fields.Append("id",ADODB.DataTypeEnum.adVarChar ,16
,ADODB.FieldAttributeEnum.adFldMayBeNull, null);
rs.Fields.Append("time", ADODB.DataTypeEnum.adVarChar, 10,
ADODB.FieldAttributeEnum.adFldMayBeNull, null);

object[] f = new object[3];
object[] v = new object[3];

f[0] = "type";
f[1] = "id";
f[2] = "time";

v[0] = type;
v[1] = ID;
v[2] = time;

object x = new object();
object y = new object();
x = null;
y = null;

rs.Open(x, y,
ADODB.CursorTypeEnum.adOpenStatic,ADODB.LockTypeEnum.adLockOptimistic,-1);
rs.AddNew(f,v);
rs.Update(f,v);

The null assignment for Source and Active Connection generate an error
when passed to rs.Open.

My other question is what is expected for FieldValue in the
rs.Fields.Append? Null is the only value I can pass without creating an
"invalid arguement" error.

Thanks,
Chris

Gah, ignore my previous reply about the creation of fields. There is no way
to set the value at creation time - you're creating a column defintion, not
a row in the recordset. You set the values when you add a new record.

Dan


.



Relevant Pages

  • Re: ADO 2.7 C# - How Do I Create a Recordset On-the-Fly?
    ... I'm trying to add data to a recordset that I've created on-the-fly using ... a Source and Active Connection parameter. ... The null assignment for Source and Active Connection generate an error ... I'm not sure if this is valid syntax for C#, I just copied your code and ...
    (microsoft.public.data.ado)
  • ADO 2.7 C# - How Do I Create a Recordset On-the-Fly?
    ... I'm using ADO 2.7 for compatibility with an existing component I'm using. ... I'm trying to add data to a recordset that I've created on-the-fly using C# ... Source and Active Connection parameter. ...
    (microsoft.public.data.ado)
  • Re: Disconnected Recordsets with Command Object
    ... that the Active Connection could not be changed because the Recordset had a ... the same thing but in fact each way behaves just a little differently. ... >>How do I create a disconnected recordset using the command object? ...
    (microsoft.public.data.ado)