Creating table in Access database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric Carr

    Creating table in Access database

    I have been trying to create a table in an Access database via a VB.NET
    program and I am running into a problem defining an autoincrement field. I
    am getting an error saying "Property 'Item' is 'ReadOnly'" on the line that
    SHOULD be turning this property on for the ID field. Does any one have any
    suggestions on how to do this in .NET?

    The code that I am using is:
    Dim cat As Catalog = New Catalog
    Dim tblNew As ADOX.Table = New ADOX.Table
    Dim colNew As ADOX.Column = New ADOX.Column

    cat.Create("Pro vider=Microsoft .Jet.OLEDB.4.0; " & _
    "Data Source=Reservat ions.mdb;" & _
    "Jet OLEDB:Engine Type=5")

    ' Create a new Table object.
    With tblNew
    .Name = "tblCabin"

    ' Create fields and append them to the columns collection of the new
    Table object.

    With .Columns
    .Append("ID", DataTypeEnum.ad Integer)
    .Item("ID").Par entCatalog = cat
    .Item("ID").Pro perties("AutoIn crement") = True '
    This is the line that generates the error
    .Append("Name", DataTypeEnum.ad VarWChar, 50)
    .Append("NameSh ort", DataTypeEnum.ad VarWChar, 10)
    End With
    End With

    ' Add the new Table to the Tables collection of the database.
    cat.Tables.Appe nd(tblNew)


  • Cor Ligthert

    #2
    Re: Creating table in Access database

    Hi Eric,

    You are using ADO that can be used in VB.net (however what not), but it not
    Ado.Net.
    Most of us are not using Ado anymore (I use it to create an access database,
    because that is impossible with AdoNet)

    However your problem can, so have a look for Adonet.

    Here is a link to the resource kit to have some samples for that and more.
    (There is also a sample in it using ADO when you want to keep that)



    And if you have problems installing it



    I hope this helps a little bit?

    Cor


    Comment

    • Cor Ligthert

      #3
      Re: Creating table in Access database

      Hi Eric,

      You are using ADO that can be used in VB.net (however what not), but it not
      Ado.Net.
      Most of us are not using Ado anymore (I use it to create an access database,
      because that is impossible with AdoNet)

      However your problem can, so have a look for Adonet.

      Here is a link to the resource kit to have some samples for that and more.
      (There is also a sample in it using ADO when you want to keep that)



      And if you have problems installing it



      I hope this helps a little bit?

      Cor


      Comment

      • Paul Clement

        #4
        Re: Creating table in Access database

        On Fri, 9 Apr 2004 15:15:24 -0400, "Eric Carr" <escarr.nospam@ ufl.nospam.edu> wrote:

        ¤ I have been trying to create a table in an Access database via a VB.NET
        ¤ program and I am running into a problem defining an autoincrement field. I
        ¤ am getting an error saying "Property 'Item' is 'ReadOnly'" on the line that
        ¤ SHOULD be turning this property on for the ID field. Does any one have any
        ¤ suggestions on how to do this in .NET?
        ¤
        ¤ The code that I am using is:
        ¤ Dim cat As Catalog = New Catalog
        ¤ Dim tblNew As ADOX.Table = New ADOX.Table
        ¤ Dim colNew As ADOX.Column = New ADOX.Column
        ¤
        ¤ cat.Create("Pro vider=Microsoft .Jet.OLEDB.4.0; " & _
        ¤ "Data Source=Reservat ions.mdb;" & _
        ¤ "Jet OLEDB:Engine Type=5")
        ¤
        ¤ ' Create a new Table object.
        ¤ With tblNew
        ¤ .Name = "tblCabin"
        ¤
        ¤ ' Create fields and append them to the columns collection of the new
        ¤ Table object.
        ¤
        ¤ With .Columns
        ¤ .Append("ID", DataTypeEnum.ad Integer)
        ¤ .Item("ID").Par entCatalog = cat
        ¤ .Item("ID").Pro perties("AutoIn crement") = True '
        ¤ This is the line that generates the error
        ¤ .Append("Name", DataTypeEnum.ad VarWChar, 50)
        ¤ .Append("NameSh ort", DataTypeEnum.ad VarWChar, 10)
        ¤ End With
        ¤ End With
        ¤
        ¤ ' Add the new Table to the Tables collection of the database.
        ¤ cat.Tables.Appe nd(tblNew)
        ¤

        You should include the Value property:

        Item("ID").Prop erties("AutoInc rement").Value = True

        In addition, some of these properties may need to be set *before* appending the column to the
        Columns collection.


        Paul ~~~ pclement@amerit ech.net
        Microsoft MVP (Visual Basic)

        Comment

        Working...