Converting ADO.NET DataSet to ADO Recordset - How do I set default values

  • Thread starter Thread starter Bj?rn Egil
  • Start date Start date
B

Bj?rn Egil

Hello,

I'm working on a project where we are converting between DataSet
(actually DataTable) and Recordset to support existing VB6 code. We
define the Fields of the Recordset by calling
aRecordset.Fields.Append(...). However I have not been able to find
out how I also can set the default value to be used for a Field when
creating new rows. I appreciate any help in solving this - thanks.

Best regards,
Bjørn Egil Hansen
 
On 20 Aug 2004 00:07:01 -0700, (e-mail address removed) (Bj?rn Egil) wrote:

¤ Hello,
¤
¤ I'm working on a project where we are converting between DataSet
¤ (actually DataTable) and Recordset to support existing VB6 code. We
¤ define the Fields of the Recordset by calling
¤ aRecordset.Fields.Append(...). However I have not been able to find
¤ out how I also can set the default value to be used for a Field when
¤ creating new rows. I appreciate any help in solving this - thanks.
¤
¤ Best regards,
¤ Bjørn Egil Hansen

The Field object does not provide a default value property at the Recordset level, only the database
table level with the ADOX Column object.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
If the dataset is being populated from a server you could instead use ADODB
from within ASP.NET and the recordset object would be created for you. This
might possibly get the default if it is defined in the server database.
 
Paul Clement said:
On 20 Aug 2004 00:07:01 -0700, (e-mail address removed) (Bj?rn Egil) wrote:

¤ We
¤ define the Fields of the Recordset by calling
¤ aRecordset.Fields.Append(...). However I have not been able to find
¤ out how I also can set the default value to be used for a Field when
¤ creating new rows.

The Field object does not provide a default value property at the Recordset level, only the database
table level with the ADOX Column object.
Hi Paul,
Thanks for your reply. Since I'm only working with the Recordset in
memory I guess there is no way I can make it pick up the default value
from some ADOX Column object or similar?

Cheers,
Bjørn Egil
 
On 22 Aug 2004 13:56:16 -0700, (e-mail address removed) (Bj?rn Egil) wrote:

¤ > On 20 Aug 2004 00:07:01 -0700, (e-mail address removed) (Bj?rn Egil) wrote:
¤ >
¤ > ¤ We
¤ > ¤ define the Fields of the Recordset by calling
¤ > ¤ aRecordset.Fields.Append(...). However I have not been able to find
¤ > ¤ out how I also can set the default value to be used for a Field when
¤ > ¤ creating new rows.
¤ >
¤ > The Field object does not provide a default value property at the Recordset level, only the database
¤ > table level with the ADOX Column object.
¤ >
¤ Hi Paul,
¤ Thanks for your reply. Since I'm only working with the Recordset in
¤ memory I guess there is no way I can make it pick up the default value
¤ from some ADOX Column object or similar?

If you have a Recordset then you have the Fields collection and the Name of each field. You can then
reference the Default value via ADOX. You also need to know the table name upon which the Recordset
is based:

Dim cat As New ADOX.Catalog

Set cat.ActiveConnection = cnn

DefaultValue = cat.Tables("Table1").Columns(rs.Fields(0).Name).Properties("Default").Value


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Paul Clement said:
On 22 Aug 2004 13:56:16 -0700, (e-mail address removed) (Bj?rn Egil) wrote:

¤ > On 20 Aug 2004 00:07:01 -0700, (e-mail address removed) (Bj?rn Egil) wrote:
¤ >
¤ > ¤ We
¤ > ¤ define the Fields of the Recordset by calling
¤ > ¤ aRecordset.Fields.Append(...). However I have not been able to find
¤ > ¤ out how I also can set the default value to be used for a Field when
¤ > ¤ creating new rows.
¤ >
¤ > The Field object does not provide a default value property at the Recordset level, only the database
¤ > table level with the ADOX Column object.
¤ >
¤ Hi Paul,
¤ Thanks for your reply. Since I'm only working with the Recordset in
¤ memory I guess there is no way I can make it pick up the default value
¤ from some ADOX Column object or similar?

If you have a Recordset then you have the Fields collection and the Name of each field. You can then
reference the Default value via ADOX. You also need to know the table name upon which the Recordset
is based:

Dim cat As New ADOX.Catalog

Set cat.ActiveConnection = cnn

DefaultValue = cat.Tables("Table1").Columns(rs.Fields(0).Name).Properties("Default").Value


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)

Thanks again, Paul,

Sorry for being a bit imprecise in my description: The Recordset is
generated in memory from a DataSet (where I know the default values),
and I would like the to make the Recordset use the same default values
(maybe by setting up a ADOX structure underneath it) so that new
Records added to the Recordset will have these default values
initially.

So is there any way to set up ADOX structure without a connection to a
database?

Cheers,
Bjørn Egil
 
On 27 Aug 2004 04:09:18 -0700, (e-mail address removed) (Bj?rn Egil) wrote:

¤ > On 22 Aug 2004 13:56:16 -0700, (e-mail address removed) (Bj?rn Egil) wrote:
¤ >
¤ > ¤ > On 20 Aug 2004 00:07:01 -0700, (e-mail address removed) (Bj?rn Egil) wrote:
¤ > ¤ >
¤ > ¤ > ¤ We
¤ > ¤ > ¤ define the Fields of the Recordset by calling
¤ > ¤ > ¤ aRecordset.Fields.Append(...). However I have not been able to find
¤ > ¤ > ¤ out how I also can set the default value to be used for a Field when
¤ > ¤ > ¤ creating new rows.
¤ > ¤ >
¤ > ¤ > The Field object does not provide a default value property at the Recordset level, only the database
¤ > ¤ > table level with the ADOX Column object.
¤ > ¤ >
¤ > ¤ Hi Paul,
¤ > ¤ Thanks for your reply. Since I'm only working with the Recordset in
¤ > ¤ memory I guess there is no way I can make it pick up the default value
¤ > ¤ from some ADOX Column object or similar?
¤ >
¤ > If you have a Recordset then you have the Fields collection and the Name of each field. You can then
¤ > reference the Default value via ADOX. You also need to know the table name upon which the Recordset
¤ > is based:
¤ >
¤ > Dim cat As New ADOX.Catalog
¤ >
¤ > Set cat.ActiveConnection = cnn
¤ >
¤ > DefaultValue = cat.Tables("Table1").Columns(rs.Fields(0).Name).Properties("Default").Value
¤ >
¤ >
¤ > Paul ~~~ (e-mail address removed)
¤ > Microsoft MVP (Visual Basic)
¤
¤ Thanks again, Paul,
¤
¤ Sorry for being a bit imprecise in my description: The Recordset is
¤ generated in memory from a DataSet (where I know the default values),
¤ and I would like the to make the Recordset use the same default values
¤ (maybe by setting up a ADOX structure underneath it) so that new
¤ Records added to the Recordset will have these default values
¤ initially.
¤
¤ So is there any way to set up ADOX structure without a connection to a
¤ database?

No, ADOX requires a connection to the database. You can use either an ADO Connection object or a
connection string.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Back
Top