Problem creating a required Yes/No field using ADOX

D

Dhar Rawal

Hi,

I am using ADOX with Jet 4.0 to create a database table that has a yes/no
field. I can create the field just fine. I am using VC++ 6.0.

But I just cannot set it's required property to true.

I have tried the following:
1) spTargetColumn->Attributes =
static_cast<ColumnAttributesEnum>(adColFixed); // using attributes
=> This has absolutely no effect

2) ADODB::propertyPtr spTargetProperty =
spTargetColumn->Properties->Item[variant_t(L"Nullable")]->PutValue(vt_Nullab
le);
=> This throws an exception with the following error description:
"Multiple-step OLE DB operation generated errors. Check each OLE DB status
value, if available. No work was done."

I am wondering what I could be doing wrong.

Please help!

Best Regards,
Dhar


p.s. I am a MSDN universal subscriber
 
G

GVaught

yes/no boxes equate to -1 (True/Yes) and 0 (False/No) in Access.
Thus, based on a condition your statement may look like this.

If somefield = >= 10 Then
Me.YesNobox = "True"
Else
Me.YesNobox = "False"
End If
 
D

Dhar Rawal

Hi GVaught,

I am using VC++ 6.0 with ADOX. I am creating a schema migration COM
component, that can migrate access database schema changes between our
application versions.

It sounds like you are under the impression that I am programming on the
Access platform. Not So!

Perhaps, I should be posting to a different newsgroup, but I could not find
one for ADOX

Best Regards,
Dhar


GVaught said:
yes/no boxes equate to -1 (True/Yes) and 0 (False/No) in Access.
Thus, based on a condition your statement may look like this.

If somefield = >= 10 Then
Me.YesNobox = "True"
Else
Me.YesNobox = "False"
End If


Dhar Rawal said:
Hi,

I am using ADOX with Jet 4.0 to create a database table that has a yes/no
field. I can create the field just fine. I am using VC++ 6.0.

But I just cannot set it's required property to true.

I have tried the following:
1) spTargetColumn->Attributes =
static_cast<ColumnAttributesEnum>(adColFixed); // using attributes
=> This has absolutely no effect

2) ADODB::propertyPtr spTargetProperty =
spTargetColumn->Properties->Item[variant_t(L"Nullable")]->PutValue(vt_Nullab
le);
=> This throws an exception with the following error description:
"Multiple-step OLE DB operation generated errors. Check each OLE DB status
value, if available. No work was done."

I am wondering what I could be doing wrong.

Please help!

Best Regards,
Dhar


p.s. I am a MSDN universal subscriber
 
B

Brendan Reynolds \(MVP\)

I don't have an answer to your question, Dhar, but I can confirm (if any
confirmation was needed) that the problem is not in any way unique to VC++.
I get the same error message trying to do the same thing in VBA.

I hope someone else may be able to answer your question, but in my
experience most Access developers don't make much use of ADOX. When working
with Jet databases, it's much easier to use DAO, with which most of us are
more familiar. In VBA, the same thing can be done using DAO in a single line
of code ...

CurrentDb.TableDefs("tblTest").Fields("TestBool").Required = True

CurrentDb won't be available outside of Access, of course, you'd need to use
OpenDatabase to get a reference to the Jet database.

BTW: There's actually no point in setting the Required property of a Jet
Boolean (Yes/No) field, as it can only return -1 or 0. If no value was ever
assigned to the field, it will return 0. It will never return Null. (You can
assign a Null value to the field, and the code will run without error, but
if you then retrieve the value from the same field, in the same record, to
which you just assigned a Null value, you'll get back 0, not Null.)

--
Brendan Reynolds (MVP)
(e-mail address removed)


Dhar Rawal said:
Hi GVaught,

I am using VC++ 6.0 with ADOX. I am creating a schema migration COM
component, that can migrate access database schema changes between our
application versions.

It sounds like you are under the impression that I am programming on the
Access platform. Not So!

Perhaps, I should be posting to a different newsgroup, but I could not find
one for ADOX

Best Regards,
Dhar


GVaught said:
yes/no boxes equate to -1 (True/Yes) and 0 (False/No) in Access.
Thus, based on a condition your statement may look like this.

If somefield = >= 10 Then
Me.YesNobox = "True"
Else
Me.YesNobox = "False"
End If
spTargetColumn->Properties->Item[variant_t(L"Nullable")]->PutValue(vt_Nullab
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top