Access 2000 Required Fields

  • Thread starter Thread starter Eric Johanson
  • Start date Start date
E

Eric Johanson

Hi

I am trying to get ADO.NET and Access to work together
nicely and part of the process is to read the 'Required'
property of each column in an Access database. I've used
the same code with ADO.NET against SQL Server 2000 and a
column's 'AllowDBNull' property is always properly set,
however, with Access 2000 it is always set to false?

summary of code:
myAdapter.FillSchema(myTable)
blnAllowNull = myTable.Columns(0).AllowDBNull

Does anyone know of a way to find this out using ADO.NET.
I can get the same info using ADOX & COM but I'd rather
keep it all .NET.

Thanks

Eric
 
¤ Hi
¤
¤ I am trying to get ADO.NET and Access to work together
¤ nicely and part of the process is to read the 'Required'
¤ property of each column in an Access database. I've used
¤ the same code with ADO.NET against SQL Server 2000 and a
¤ column's 'AllowDBNull' property is always properly set,
¤ however, with Access 2000 it is always set to false?
¤
¤ summary of code:
¤ myAdapter.FillSchema(myTable)
¤ blnAllowNull = myTable.Columns(0).AllowDBNull
¤
¤ Does anyone know of a way to find this out using ADO.NET.
¤ I can get the same info using ADOX & COM but I'd rather
¤ keep it all .NET.
¤

Give the following a try:

Sub ListTableSchema()

Dim AccessConnection As New System.Data.OleDb.OleDbConnection()
Dim SchemaTable As DataTable

AccessConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=E:\My Documents\db1.mdb"
AccessConnection.Open()

'Retrieve schema information about Table1.
SchemaTable =
AccessConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Columns, _
New Object() {Nothing, Nothing, "Table1"})

Dim RowCount As Int32
For RowCount = 0 To SchemaTable.Rows.Count - 1
Console.WriteLine(SchemaTable.Rows(RowCount)!COLUMN_NAME.ToString)
Console.WriteLine(SchemaTable.Rows(RowCount)!IS_NULLABLE.ToString)
Next RowCount

DataGrid1.DataSource = SchemaTable

AccessConnection.Close()

End Sub


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Thanks Paul it works like a charm :-)

Not sure why I didn't see this...
.... .NET's just so BIG!
 
Back
Top