Problems usin ADO from C#

Problems usin ADO from C#

Post by <itexp.. » Thu, 01 Aug 2002 03:21:53



Can somebody help me to
program this code

ADODB.Connection cnn;
ADODB.Recordset rec;
cnn.Open(ConnectionString,"","",-1);
rec=cnn.Execute(......);
rec.MoveFirst();
object val=rec.Fields[1].Value;

using Reflection namespace to be version independent from ADO.
I know it must look like this:
Type cnnType=Type.GetTypeFromProgID("ADODB.Connection");
Type recType=Type.GetTypeFromProgID("ADODB.Recordset");
Type FieldType;
Type FieldsType;
cnnType.GetProperty("ConnectionString").SetValue(cnn,Destination.ConnectionS
tring,null);
cnnType.GetMethod("Open").Invoke(cnn,new object[]{"","","",-1});
rec=Activator.CreateInstance(recType);
object [] args=new object[5];
args[0]=Tablename;
args[1]=cnn;
......
args[4]=-1;
recType.GetMethod("Open").Invoke(rec,args);
object [] index=new object [1];
index[0]=1;

object Field=recType.GetProperty("Fields").GetValue(ImpRecordset,index); But
there is returned null.
Can sombody explain me why?

FieldType=typeof(Field);
object Value=FieldType.GetProperty("Value").GetValue(Field,null);