Note that there are some explanatory texts on larger screens.

plurals
  1. PO"Nullable" property for ADOX table column?
    primarykey
    data
    text
    <p>I'm trying to create an Access file (.mdb) with C#. I'm exporting data from SQL for a legacy process. I got it working, the only problem I'm facing is setting columns to nullable.</p> <p>Here's what I have (removed most columns for brevity):</p> <pre><code>private void CreateAndExportLegacyFile(DataTable data, string exportFilename) { var connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;"; connectionString += "Data Source=" + exportFilename + ";Jet OLEDB:Engine Type=5"; var catalog = new Catalog(); catalog.Create(connectionString); var table = new Table { Name = "Main" }; #region Column mapping table.Columns.Append("ID", DataTypeEnum.adVarWChar, 50); table.Columns.Append("FIRST", DataTypeEnum.adVarWChar, 50); table.Columns.Append("LAST", DataTypeEnum.adVarWChar, 50); #endregion foreach (Column column in table.Columns) { if (column.Name != "ID") column.Properties["Nullable"].Value = true; } catalog.Tables.Append(table); Marshal.FinalReleaseComObject(table); Marshal.FinalReleaseComObject(catalog.Tables); Marshal.FinalReleaseComObject(catalog.ActiveConnection); Marshal.FinalReleaseComObject(catalog); } </code></pre> <p>I get the following error when trying to set the "Nullable" property: "Item cannot be found in the collection corresponding to the requested name or ordinal."</p> <p>I've found conflicting reports of whether to use Required or Nullable, but I've tried both and get the same result.</p> <p>Any idea why I'm not able to set the nullable property? I may just be lazy and default nulls to blank spaces when pulling the data, but would like to avoid that if possible.</p> <p><strong>Edit</strong>: As Hans mentioned in a comment, I had to use the Attributes property instead:</p> <pre><code>if (column.Name != "ID") column.Attributes = ColumnAttributesEnum.adColNullable; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload