none
how to specify the default value and the nullability of the new added column in msaccess using ADOX and C# RRS feed

  • Question

  • As explained here http://allenbrowne.com/func-adox.html#ModifyTableAdox
    I added new column using ADOX and C# to my ms access table
    How do I specify the default value and nullabilty of the newly added column

    Sample code is as follows


    Dim cat As New ADOX.Catalog
        Dim tbl As ADOX.Table
        Dim col As New ADOX.Column
       
        'Initialize
        cat.ActiveConnection = CurrentProject.Connection
        Set tbl = cat.Tables("tblAdoxContractor")
       
        'Add a new column
        With col
            .Name = "MyDecimal"
            .Type = adNumeric   'Decimal type.
            .Precision = 28     '28 digits.
            .NumericScale = 8   '8 decimal places.
        End With
        tbl.Columns.Append col
    //This statement gives compilation error as ADOX.Properties is read only
    col.Properties["Nullable"]=false;

    Thanks in advance.


    Rajesh S Harwani

    Wednesday, April 30, 2014 11:18 AM

Answers

All replies

  • Hi Rajesh,

    Use the attributes property. See more from the following reference. http://msdn.microsoft.com/en-us/library/windows/desktop/ms676554(v=vs.85).aspx.  Code like:

    if (column.Name != "ID") column.Attributes = ColumnAttributesEnum.adColNullable;

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 1, 2014 2:29 AM
    Moderator
  • You have shown how to set the nullable property.

    But my second question is how to set the default value for the column?


    Rajesh S Harwani

    Friday, May 2, 2014 8:55 AM
  • Got it

    The code is

    col.Properties[

    "Default"].Value = 100;

    Rajesh S Harwani

    Friday, May 2, 2014 8:58 AM