Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. create a runtime table in Ms Access database

create a runtime table in Ms Access database

Scheduled Pinned Locked Moved C#
csharpasp-netdatabasetutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    arpita2006
    wrote on last edited by
    #1

    I want to create table at runtime for an existing Ms Access database using ASP.net 2.0 and C#. Can anyone please guide me through it ?

    E L 2 Replies Last reply
    0
    • A arpita2006

      I want to create table at runtime for an existing Ms Access database using ASP.net 2.0 and C#. Can anyone please guide me through it ?

      E Offline
      E Offline
      Eduard Keilholz
      wrote on last edited by
      #2

      use the CREATE TABLE statement CREATE TABLE tablename( COLUMNS )

      .: I love it when a plan comes together :. http://www.zonderpunt.nl

      1 Reply Last reply
      0
      • A arpita2006

        I want to create table at runtime for an existing Ms Access database using ASP.net 2.0 and C#. Can anyone please guide me through it ?

        L Offline
        L Offline
        lost in transition
        wrote on last edited by
        #3

        Here are two SQL statements that will create table1 and then create table2 with PK, FK and inforced integrity. string _StrSQL; string tblName = "table1"; string tblName2 = "table2"; _StrSQL = @"CREATE TABLE " + tblName + @" (RecID AUTOINCREMENT " + @" CONSTRAINT PK_" + tblName + " PRIMARY KEY, " + @" RecorderID VARCHAR WITH COMPRESSION, " + @" GroupID VARCHAR WITH COMPRESSION, " + @" Name VARCHAR WITH COMPRESSION, " + @" Address VARCHAR WITH COMPRESSION)"; _StrSQL = @"CREATE TABLE " + tblName + @"(HourID AUTOINCREMENT" + @" CONSTRAINT PK_" + tblName + " PRIMARY KEY," + @" RecID INTEGER NOT NULL " + @" CONSTRAINT FK_" + tblName2 + "_" + tblName + @" REFERENCES " + tblName2 + " (RecID) " + @" ON UPDATE CASCADE " + @" ON DELETE CASCADE," + @" DSID INTEGER NOT NULL," + @" [Month] INTEGER," + @" [Day] INTEGER," + @" [Year] INTEGER," + @" [Hour] INTEGER)"; You do not have to use the '@' symboly. I use it because it make the statement easier on my eyes. Then drop the _StrSQL in a OleDbCommand: object _obj = null; OleDbConnection OleConn = new OleDbConnection(_ConnString); OleDbCommand OleComm = new OleDbCommand(_SQLString, OleConn); OleComm.Connection.Open(); _obj = OleComm.ExecuteScalar(); OleComm.Connection.Close(); Good Luck, Jason

        Programmer: A biological machine designed to convert caffeine into code. * Developer: A person who develops working systems by writing and using software. [^]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups