with CDaoRecordSet is it possible to change a field definition ?

i have a table with a text field whose definition does not allow empty string;
now i want to change this field definition to allow empty strings;

the table already has records so i can't simply delete the delete the field with CDaoTableDef::DeleteField
then recreate it  (CDaoTableDef::CreateField).

I don't see how to do that neither by the Cdao classes nor by SQL
JP_GobletAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
from DBDAOINT.H

#define INTERFACE _DAOField
DECLARE_INTERFACE_(_DAOField, _DAO)
      {
      STDMETHOD(get_CollatingOrder)                         (THIS_ long FAR* pl) PURE;
      STDMETHOD(get_Type)                                           (THIS_ short FAR* ps) PURE;
      STDMETHOD(put_Type)                                           (THIS_ short Type) PURE;
      STDMETHOD(get_Name)                                           (THIS_ BSTR FAR* pbstr) PURE;
      STDMETHOD(put_Name)                                           (THIS_ BSTR Name) PURE;
      STDMETHOD(get_Size)                                           (THIS_ long FAR* pl) PURE;
      STDMETHOD(put_Size)                                           (THIS_ long Size) PURE;
      STDMETHOD(get_SourceField)                               (THIS_ BSTR FAR* pbstr) PURE;
      STDMETHOD(get_SourceTable)                               (THIS_ BSTR FAR* pbstr) PURE;
      STDMETHOD(get_Value)                                     (THIS_ VARIANT FAR* pvar) PURE;
      STDMETHOD(put_Value)                                     (THIS_ VARIANT Val) PURE;
      STDMETHOD(get_Attributes)                               (THIS_ long FAR* pl) PURE;
      STDMETHOD(put_Attributes)                               (THIS_ long Attr) PURE;
      STDMETHOD(get_OrdinalPosition)                         (THIS_ short FAR* ps) PURE;
      STDMETHOD(put_OrdinalPosition)                         (THIS_ short Pos) PURE;
      STDMETHOD(get_ValidationText)                         (THIS_ BSTR FAR* pbstr) PURE;
      STDMETHOD(put_ValidationText)                         (THIS_ BSTR bstr) PURE;
      STDMETHOD(get_ValidateOnSet)                         (THIS_ VARIANT_BOOL FAR* pb) PURE;
      STDMETHOD(put_ValidateOnSet)                         (THIS_ VARIANT_BOOL Validate) PURE;
      STDMETHOD(get_ValidationRule)                         (THIS_ BSTR FAR* pbstr) PURE;
      STDMETHOD(put_ValidationRule)                         (THIS_ BSTR bstr) PURE;
      STDMETHOD(get_DefaultValue)                               (THIS_ VARIANT FAR* pvar) PURE;
      STDMETHOD(put_DefaultValue)                               (THIS_ VARIANT var) PURE;
      STDMETHOD(get_Required)                                     (THIS_ VARIANT_BOOL FAR* pb) PURE;
      STDMETHOD(put_Required)                                     (THIS_ VARIANT_BOOL fReq) PURE;
      STDMETHOD(get_AllowZeroLength)                         (THIS_ VARIANT_BOOL FAR* pb) PURE;


      STDMETHOD(put_AllowZeroLength)                         (THIS_ VARIANT_BOOL fAllow) PURE;     <-----------------------


      STDMETHOD(get_DataUpdatable)                         (THIS_ VARIANT_BOOL FAR* pb) PURE;
      STDMETHOD(get_ForeignName)                               (THIS_ BSTR FAR* pbstr) PURE;
      STDMETHOD(put_ForeignName)                               (THIS_ BSTR bstr) PURE;
      STDMETHOD(AppendChunk)                                     (THIS_ VARIANT Val) PURE;
      STDMETHOD(GetChunk)                                           (THIS_ long Offset, long Bytes, VARIANT FAR* pvar) PURE;
      STDMETHOD(_30_FieldSize)                               (THIS_ long FAR* pl) PURE;
      STDMETHOD(CreateProperty)                               (THIS_ VARIANT Name, VARIANT Type, VARIANT Value, VARIANT DDL, DAOProperty FAR* FAR* pprp) PURE;
      STDMETHOD(get_CollectionIndex)                         (THIS_ short FAR* i) PURE;
      STDMETHOD(get_OriginalValue)                         (THIS_ VARIANT FAR* pvar) PURE;
      STDMETHOD(get_VisibleValue)                               (THIS_ VARIANT FAR* pvar) PURE;
      STDMETHOD(get_FieldSize)                               (THIS_ long FAR* pl) PURE;
      };


This might work.
void ChangeFieldRequired(CDaoDatabase* pDB, LPCTSTR pszTblName, LPCTSTR pszFieldName, bool bRequired)
{
      DAOField* pField = NULL;
      DAOFields* pFields = NULL;

      CDaoTableDef tbl(pDB);
      tbl.Open(pszTblName);

            tbl.m_pDAOTableDef->get_Fields(&pFields);
            COleVariant vName(pszFieldName,VT_BSTRT);      
            pFields->get_Item(vName, &pField);

            pField->put_AllowZeroLength((short)bRequired);    <----------------------------------------
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JP_GobletAuthor Commented:
it works, thanks;
and i can also with the same method (accessing the DAO objects hidden within the CDao objects) rename a field, modify attributes of a relation, ...
0
AndyAinscowFreelance programmer / ConsultantCommented:
It's neat, it took me a while to find this functionality some time ago.  Not everything available in DAO is exposed by the CDao classes (unfortunately).
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.