creating tables or fields in access from asp

Results 1 to 2 of 2

Thread: creating tables or fields in access from asp

  1. #1
    asp wanna be Guest

    Default creating tables or fields in access from asp

    can this be done? example....some one puts in a name, can aasp then create a table or field for this persons informatio?

  2. #2
    Ben Jones Guest

    Default RE: creating tables or fields in access from asp

    I&#039ve never tried to dynamically add fields to an Access database from ASP, however there is an SQL command called ALTER TABLE which may be used to perform exactly that function on SQL Server, Oracle, etc.<BR><BR>I&#039m not sure that you really want to get into dynamically creating fields anyways. Tables, on the other hand, can be very useful to create on the fly, and you should almost certainly be able to use the following code to do so in Access. I don&#039t know the exact syntax to create tables in SQL in Access (it uses different datatypes than SQL Server, which is what I&#039m used to). Nonetheless, this would work in SQL Server:<BR><BR>&#060;%<BR><BR>LF = chr(10)<BR><BR>sSQL = "CREATE TABLE new_table (" & LF<BR>sSQL = sSQL & "primary_key_field int NOT NULL primary key identity," & LF<BR>sSQL = sSQL & "first_name varchar(25) NULL," & LF<BR>sSQL = sSQL & "last_name varchar(25) NULL" & LF<BR>sSQL = sSQL & ")" & LF<BR><BR>set Conn = server.createObject("ADODB.connection")<BR>Conn.op en "[DSN];[username];[password];"<BR>set RS = Conn.Execute(sSQL)<BR><BR>Conn.Close<BR>set Conn = nothing<BR>set RS = nothing<BR><BR>&#037;&#062;<BR><BR>Of course, no dba would ever want to create a new table on the fly to store people&#039s names, but this is just for demonstrative purposes. If I were to hazard a guess at the syntax in Access, I would guess the following:<BR><BR>&#060;%<BR><BR>LF = chr(10)<BR><BR>sSQL = "CREATE TABLE new_table (" & LF<BR>sSQL = sSQL & "primary_key_field autonumber NOT NULL," & LF<BR>sSQL = sSQL & "first_name text(25) NULL," & LF<BR>sSQL = sSQL & "last_name text(25) NULL" & LF<BR>sSQL = sSQL & ")" & LF<BR><BR>set Conn = server.createObject("ADODB.connection")<BR>Conn.op en "[DSN];[username];[password];"<BR>set RS = Conn.Execute(sSQL)<BR><BR>Conn.Close<BR>set Conn = nothing<BR>set RS = nothing<BR><BR>&#037;&#062;<BR><BR>The "autonumber" portion may require an additional parameter (e.g., "autonumber(1)") for the seed value. Again, I&#039m not sure as I don&#039t work in Access.<BR><BR>Hope this helps you out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •