|
 |
asp_databases thread: Creating a table
Message #1 by "Rich" <ripatt@e...> on Fri, 23 Mar 2001 11:32:40 -0500
|
|
Is there a way to dynamically create a table in a Access database
from an ASP page.
Help would be greatly appreciated.
Thanks, Rich
Message #2 by "Tomm Matthis" <matthis@b...> on Fri, 23 Mar 2001 12:01:40 -0500
|
|
"CREATE TABLE xxxx ...."
Check BOL or HELP for more info...
Tomm
> -----Original Message-----
> From: Rich [mailto:ripatt@e...]
> Sent: Friday, March 23, 2001 11:33 AM
> To: ASP Databases
> Subject: [asp_databases] Creating a table
>
>
> Is there a way to dynamically create a table in a Access database
> from an ASP page.
> Help would be greatly appreciated.
> Thanks, Rich
Message #3 by "Oliver Tomkins" <oliver.tomkins@g...> on Fri, 23 Mar 2001 17:08:05 -0000
|
|
Rich, could do with a bit more information.
Why exactly do you want to create a new table?
> -----Original Message-----
> From: Rich [mailto:ripatt@e...]
> Sent: 23 March 2001 16:33
> To: ASP Databases
> Subject: [asp_databases] Creating a table
>
>
> Is there a way to dynamically create a table in a Access database
> from an ASP page.
> Help would be greatly appreciated.
> Thanks, Rich
Message #4 by Imar Spaanjaars <Imar@S...> on Sat, 24 Mar 2001 11:45:31 +0100
|
|
Yes, you can. You can either use ADOX which lets you even create new Access
databases, or you can use standard "CREATE TABLE" SQL statements, more or
less the same way you would execute a SELECT query through an ADO
connection for example.
Following is an example of using ADOX:
I think the code will describe itself. But if you still have questions, or
have trouble with the wrapping of the code, let me know.
Hope this helps,
Imar
<CODE>
Dim sDatabaseName
sDatabaseName = "C:\testDatabase.mdb"
' Add a table and columns to this database
CreateAccessTable sDatabaseName
Sub CreateAccessTable(strDBPath)
Dim catDB ' As ADOX.Catalog
Set catDB = Server.CreateObject("ADOX.Catalog")
Dim tblNew ' As ADOX.Table
Set tblNew = Server.CreateObject("ADOX.Table")
' Open the catalog.
catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDBPath
' First Create an Autonumber column, called ID. This is just for
demonstration.
' I could have done this below with all the other columns as well
Dim col ' As ADOX.Column
Set col = Server.CreateObject("ADOX.Column")
With col
.ParentCatalog = catDB
.Type = adInteger
.Name = "ID"
.Properties("Autoincrement") = True
End With
tblNew.Columns.Append col
' Now add the rest of the columns
With tblNew
.Name = "Contacts"
' Create fields and append them to the
' Columns collection of the new Table object.
With .Columns
.Append "aNumberColumn", adInteger
.Append "FirstName", adVarWChar
.Append "LastName", adVarWChar
.Append "Phone", adVarWChar
.Append "Notes", adLongVarWChar
End With
Dim adColNullable ' Is not defined in
adovbs.inc, so do it by hand.
' Other option is:
'adColFixed with a
value of 1
adColNullable = 2
With .Columns("FirstName")
.Attributes = adColNullable
End With
End With
' Add the new Table to the Tables collection of the database.
catDB.Tables.Append tblNew
Set Col = Nothing
Set tblNew = Nothing
Set catDB = Nothing
End Sub
</code>
At 11:32 AM 3/23/2001 -0500, you wrote:
>Is there a way to dynamically create a table in a Access database
>from an ASP page.
>Help would be greatly appreciated.
>Thanks, Rich
>
Message #5 by "Ian Richardson" <ian@i...> on Sat, 24 Mar 2001 14:50:22
|
|
Imar, I am joining this thread half-way through but I am trying to do
exactly the same thing, create a new db table from within an existing db.
I have tried your code as is in an asp page. I have just place your code
and a submit button on the page. the idea is to click the button and
create the db table.
I am getting the following error
'The application is using arguments that are of the wrong type, are out of
acceptable range, or are in conflict with one another.
/wdk/create.asp, line 28'
Area Line 28 reads:
With col
.ParentCatalog = catDB
.Type = adInteger
.Name = "ID"
.Properties("Autoincrement") = True
End With
Line 28 tblNew.Columns.Append col
' Now add the rest of the columns
With tblNew
.Name = "Contacts"
' Create fields and append them to the
I am just trying to create a table as is specified in your code so the
only thing I have changes is the path to the db. I would appreciate any
help.
cheers
Message #6 by Imar Spaanjaars <Imar@S...> on Mon, 26 Mar 2001 00:56:21 +0200
|
|
Hi there,
It sounds like you need to define your ADO constants. Either include the
adovbs.inc file somehow, or include a reference to your ADO dll in your
global.asa with the following code:
<GLOBAL ASA>
<!--METADATA TYPE="TypeLib" NAME="Microsoft ActiveX Data Objects
2.6 Library" UUID="{00000206-0000-0010-8000-00AA006D2EA4}" VERSION="2.6"-->
</GLOBAL ASA>
You may have to change the code / GUID to reflect your version of ADO.
Hope this helps,
Imar
At 02:50 PM 3/24/2001 +0000, you wrote:
>Imar, I am joining this thread half-way through but I am trying to do
>exactly the same thing, create a new db table from within an existing db.
>I have tried your code as is in an asp page. I have just place your code
>and a submit button on the page. the idea is to click the button and
>create the db table.
>I am getting the following error
>
>'The application is using arguments that are of the wrong type, are out of
>acceptable range, or are in conflict with one another.
>
>/wdk/create.asp, line 28'
>
>Area Line 28 reads:
> With col
> .ParentCatalog = catDB
> .Type = adInteger
> .Name = "ID"
> .Properties("Autoincrement") = True
> End With
>Line 28 tblNew.Columns.Append col
> ' Now add the rest of the columns
> With tblNew
> .Name = "Contacts"
> ' Create fields and append them to the
>
>I am just trying to create a table as is specified in your code so the
>only thing I have changes is the path to the db. I would appreciate any
>help.
>
>cheers
Message #7 by "Ian Richardson" <ian@i...> on Mon, 26 Mar 2001 09:39:40 +0100
|
|
Hi Imar,
Thanks for the pointers, the script now appears to be working in that it
executes, produces no error messages and reads down to my 'Success'
message. However, I cannot find any db table in the specified db. Do you
have any ideas why or am I missing something really obvious?
Cheers
-----Original Message-----
From: Imar Spaanjaars [mailto:Imar@S...]
Sent: 25 March 2001 23:56
To: ASP Databases
Subject: [asp_databases] Re: Creating a table
Hi there,
It sounds like you need to define your ADO constants. Either include the
adovbs.inc file somehow, or include a reference to your ADO dll in your
global.asa with the following code:
<GLOBAL ASA>
<!--METADATA TYPE="TypeLib" NAME="Microsoft ActiveX Data Objects
2.6 Library" UUID="{00000206-0000-0010-8000-00AA006D2EA4}" VERSION="2.6"-->
</GLOBAL ASA>
You may have to change the code / GUID to reflect your version of ADO.
Hope this helps,
Imar
At 02:50 PM 3/24/2001 +0000, you wrote:
>Imar, I am joining this thread half-way through but I am trying to do
>exactly the same thing, create a new db table from within an existing db.
>I have tried your code as is in an asp page. I have just place your code
>and a submit button on the page. the idea is to click the button and
>create the db table.
>I am getting the following error
>
>'The application is using arguments that are of the wrong type, are out of
>acceptable range, or are in conflict with one another.
>
>/wdk/create.asp, line 28'
>
>Area Line 28 reads:
> With col
> .ParentCatalog = catDB
> .Type = adInteger
> .Name = "ID"
> .Properties("Autoincrement") = True
> End With
>Line 28 tblNew.Columns.Append col
> ' Now add the rest of the columns
> With tblNew
> .Name = "Contacts"
> ' Create fields and append them to the
>
>I am just trying to create a table as is specified in your code so the
>only thing I have changes is the path to the db. I would appreciate any
>help.
>
>cheers
Message #8 by Imar Spaanjaars <Imar@S...> on Mon, 26 Mar 2001 18:12:06 +0200
|
|
Hi Ian,
Can you post the code for the complete page and for the bit in Global.asa??
Maybe something else is causing the problem.
Did you create complete database with ADOX or did you just try to add a
table? Make sure your user (IUSR_MachineName) has enough permissions to
write to the database
Imar
At 09:39 AM 3/26/2001 +0100, you wrote:
>Hi Imar,
>
>Thanks for the pointers, the script now appears to be working in that it
>executes, produces no error messages and reads down to my 'Success'
>message. However, I cannot find any db table in the specified db. Do you
>have any ideas why or am I missing something really obvious?
>Cheers
>
>-----Original Message-----
>From: Imar Spaanjaars [mailto:Imar@S...]
>Sent: 25 March 2001 23:56
>To: ASP Databases
>Subject: [asp_databases] Re: Creating a table
>
>
>Hi there,
>
>It sounds like you need to define your ADO constants. Either include the
>adovbs.inc file somehow, or include a reference to your ADO dll in your
>global.asa with the following code:
>
><GLOBAL ASA>
> <!--METADATA TYPE="TypeLib" NAME="Microsoft ActiveX Data Objects
>2.6 Library" UUID="{00000206-0000-0010-8000-00AA006D2EA4}" VERSION="2.6"-->
></GLOBAL ASA>
>
>You may have to change the code / GUID to reflect your version of ADO.
>
>Hope this helps,
>
>Imar
>
>
>At 02:50 PM 3/24/2001 +0000, you wrote:
> >Imar, I am joining this thread half-way through but I am trying to do
> >exactly the same thing, create a new db table from within an existing db.
> >I have tried your code as is in an asp page. I have just place your code
> >and a submit button on the page. the idea is to click the button and
> >create the db table.
> >I am getting the following error
> >
> >'The application is using arguments that are of the wrong type, are out of
> >acceptable range, or are in conflict with one another.
> >
> >/wdk/create.asp, line 28'
> >
> >Area Line 28 reads:
> > With col
> > .ParentCatalog = catDB
> > .Type = adInteger
> > .Name = "ID"
> > .Properties("Autoincrement") = True
> > End With
> >Line 28 tblNew.Columns.Append col
> > ' Now add the rest of the columns
> > With tblNew
> > .Name = "Contacts"
> > ' Create fields and append them to the
> >
> >I am just trying to create a table as is specified in your code so the
> >only thing I have changes is the path to the db. I would appreciate any
> >help.
> >
> >cheers
Message #9 by "Ian Richardson" <ian@i...> on Mon, 26 Mar 2001 21:13:03 +0100
|
|
So Imar.. where were we?
below is the code from the global asa and my web page
I am not too aware of adox although I have downloaded and installed the MDAC
2.6 SDK with Jet v 4.0 sp3. I am running from a W98 desktop, PWS and Access
2000. I also have SQL Server 7, will this code produce results if I use SQL
7?
cheers
**********global asa************
Sub Session_OnStart
Session.LCID = 1057
Session("Accepted") = 0
End Sub
Sub Session_OnEnd
Session.Abandon
End Sub
Sub Application_OnStart
<!--METADATA TYPE="TypeLib" NAME="Microsoft ActiveX Data Objects 2.6
Library" UUID="{00000206-0000-0010-8000-00AA006D2EA4}" VERSION="2.6"-->
End Sub
Sub Application_OnEnd
End Sub
*********end global***************
**********web page**************
<% @language="VBScript" %>
<%
Dim sDatabaseName
sDatabaseName = "C:\wdk\data\details.mdb"
Sub CreateAccessTable(strDBPath)
Dim catDB ' As ADOX.Catalog
Set catDB = Server.CreateObject("ADOX.Catalog")
Dim tblNew ' As ADOX.Table
Set tblNew = Server.CreateObject("ADOX.Table")
' Open the catalog.
catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDBPath
' First Create an Autonumber column, called ID. This is just for
demonstration.
' I could have done this below with all the other columns as well
Dim col ' As ADOX.Column
Set col = Server.CreateObject("ADOX.Column")
With col
.ParentCatalog = catDB
.Type = adInteger
.Name = "ID"
.Properties("Autoincrement") = True
End With
tblNew.Columns.Append col
' Now add the rest of the columns
With tblNew
.Name = "Contacts"
' Create fields and append them to the
' Columns collection of the new Table object.
With .Columns
.Append "aNumberColumn", adInteger
.Append "FirstName", adVarWChar
.Append "LastName", adVarWChar
.Append "Phone", adVarWChar
.Append "Notes", adLongVarWChar
End With
Dim adColNullable ' Is not defined in
adovbs.inc, so do it by hand.
' Other option is:
'adColFixed with a
value of 1
adColNullable = 2
With .Columns("FirstName")
.Attributes = adColNullable
End With
End With
' Add the new Table to the Tables collection of the database.
catDB.Tables.Append tblNew
Set Col = Nothing
Set tblNew = Nothing
Set catDB = Nothing
End Sub
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>Untitled</TITLE>
</HEAD>
<BODY>
table created
<form action="create.asp" method="POST">
<input type="Submit" name="cmdCreate" value="Create Client Table">
</form>
</BODY>
</HTML>
**********end web page.
-----Original Message-----
From: Imar Spaanjaars [mailto:Imar@S...]
Sent: 26 March 2001 17:12
To: ASP Databases
Subject: [asp_databases] Re: Creating a table
Hi Ian,
Can you post the code for the complete page and for the bit in Global.asa??
Maybe something else is causing the problem.
Did you create complete database with ADOX or did you just try to add a
table? Make sure your user (IUSR_MachineName) has enough permissions to
write to the database
Imar
At 09:39 AM 3/26/2001 +0100, you wrote:
>Hi Imar,
>
>Thanks for the pointers, the script now appears to be working in that it
>executes, produces no error messages and reads down to my 'Success'
>message. However, I cannot find any db table in the specified db. Do you
>have any ideas why or am I missing something really obvious?
>Cheers
>
>-----Original Message-----
>From: Imar Spaanjaars [mailto:Imar@S...]
>Sent: 25 March 2001 23:56
>To: ASP Databases
>Subject: [asp_databases] Re: Creating a table
>
>
>Hi there,
>
>It sounds like you need to define your ADO constants. Either include the
>adovbs.inc file somehow, or include a reference to your ADO dll in your
>global.asa with the following code:
>
><GLOBAL ASA>
> <!--METADATA TYPE="TypeLib" NAME="Microsoft ActiveX Data Objects
>2.6 Library" UUID="{00000206-0000-0010-8000-00AA006D2EA4}" VERSION="2.6"-->
></GLOBAL ASA>
>
>You may have to change the code / GUID to reflect your version of ADO.
>
>Hope this helps,
>
>Imar
>
>
>At 02:50 PM 3/24/2001 +0000, you wrote:
> >Imar, I am joining this thread half-way through but I am trying to do
> >exactly the same thing, create a new db table from within an existing db.
> >I have tried your code as is in an asp page. I have just place your code
> >and a submit button on the page. the idea is to click the button and
> >create the db table.
> >I am getting the following error
> >
> >'The application is using arguments that are of the wrong type, are out
of
> >acceptable range, or are in conflict with one another.
> >
> >/wdk/create.asp, line 28'
> >
> >Area Line 28 reads:
> > With col
> > .ParentCatalog = catDB
> > .Type = adInteger
> > .Name = "ID"
> > .Properties("Autoincrement") = True
> > End With
> >Line 28 tblNew.Columns.Append col
> > ' Now add the rest of the columns
> > With tblNew
> > .Name = "Contacts"
> > ' Create fields and append them to the
> >
> >I am just trying to create a table as is specified in your code so the
> >only thing I have changes is the path to the db. I would appreciate any
> >help.
> >
> >cheers
Message #10 by Imar Spaanjaars <Imar@S...> on Mon, 26 Mar 2001 22:54:39 +0200
|
|
Hi Ian,
You'll need to move the METADATA tag outside the application on start
event. You are not actually storing the object or anything in the application.
<!--METADATA TYPE="TypeLib" NAME="Microsoft ActiveX Data Objects 2.6
Library" UUID="{00000206-0000-0010-8000-00AA006D2EA4}" VERSION="2.6"-->
<script language="vbscript" runat="server">
Sub Session_OnStart
End Sub
Sub Session_OnEnd
End Sub
Sub Application_OnStart
End Sub
Sub Application_OnEnd
End Sub
</script>
(If you don' t have any code inside the events, remove it from your
global.asa file)
Next, the reason why the table is not created: you're not calling your sub.
I moved the example code to a sub to make it more reusable code. But the
sub won't be executed by itself. Try this:
Dim sDatabaseName
sDatabaseName = "C:\wdk\data\details.mdb"
' Now call the sub and pass the database name as a parameter:
CreateAccessTable(sDatabaseName)
I am pretty sure this will do the trick.
Please let me know if you got this to work.
Imar
At 09:13 PM 3/26/2001 +0100, you wrote:
>So Imar.. where were we?
>
>below is the code from the global asa and my web page
>
>I am not too aware of adox although I have downloaded and installed the MDAC
>2.6 SDK with Jet v 4.0 sp3. I am running from a W98 desktop, PWS and Access
>2000. I also have SQL Server 7, will this code produce results if I use SQL
>7?
> cheers
>
>**********global asa************
>Sub Session_OnStart
>Session.LCID = 1057
>Session("Accepted") = 0
>End Sub
>
>Sub Session_OnEnd
>Session.Abandon
>End Sub
>
>Sub Application_OnStart
> <!--METADATA TYPE="TypeLib" NAME="Microsoft ActiveX Data Objects 2.6
>Library" UUID="{00000206-0000-0010-8000-00AA006D2EA4}" VERSION="2.6"-->
>End Sub
>
>Sub Application_OnEnd
>End Sub
>*********end global***************
>
>**********web page**************
><% @language="VBScript" %>
><%
>Dim sDatabaseName
>sDatabaseName = "C:\wdk\data\details.mdb"
>
>Sub CreateAccessTable(strDBPath)
> Dim catDB ' As ADOX.Catalog
> Set catDB = Server.CreateObject("ADOX.Catalog")
> Dim tblNew ' As ADOX.Table
> Set tblNew = Server.CreateObject("ADOX.Table")
> ' Open the catalog.
> catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> "Data Source=" & strDBPath
> ' First Create an Autonumber column, called ID. This is just for
>demonstration.
> ' I could have done this below with all the other columns as well
> Dim col ' As ADOX.Column
> Set col = Server.CreateObject("ADOX.Column")
> With col
> .ParentCatalog = catDB
> .Type = adInteger
> .Name = "ID"
> .Properties("Autoincrement") = True
> End With
> tblNew.Columns.Append col
> ' Now add the rest of the columns
> With tblNew
> .Name = "Contacts"
> ' Create fields and append them to the
> ' Columns collection of the new Table object.
> With .Columns
> .Append "aNumberColumn", adInteger
> .Append "FirstName", adVarWChar
> .Append "LastName", adVarWChar
> .Append "Phone", adVarWChar
> .Append "Notes", adLongVarWChar
> End With
> Dim adColNullable ' Is not defined in
>adovbs.inc, so do it by hand.
> ' Other option is:
> 'adColFixed with a
>value of 1
> adColNullable = 2
> With .Columns("FirstName")
> .Attributes = adColNullable
> End With
> End With
> ' Add the new Table to the Tables collection of the database.
> catDB.Tables.Append tblNew
> Set Col = Nothing
> Set tblNew = Nothing
> Set catDB = Nothing
>End Sub
>%>
>
>
>
><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
>
>table created
>**********end web page.
>-----Original Message-----
>From: Imar Spaanjaars [mailto:Imar@S...]
>Sent: 26 March 2001 17:12
>To: ASP Databases
>Subject: [asp_databases] Re: Creating a table
>
>
>Hi Ian,
>
>Can you post the code for the complete page and for the bit in Global.asa??
>Maybe something else is causing the problem.
>
>Did you create complete database with ADOX or did you just try to add a
>table? Make sure your user (IUSR_MachineName) has enough permissions to
>write to the database
>
>
>Imar
>
>At 09:39 AM 3/26/2001 +0100, you wrote:
> >Hi Imar,
> >
> >Thanks for the pointers, the script now appears to be working in that it
> >executes, produces no error messages and reads down to my 'Success'
> >message. However, I cannot find any db table in the specified db. Do you
> >have any ideas why or am I missing something really obvious?
> >Cheers
> >
> >-----Original Message-----
> >From: Imar Spaanjaars [mailto:Imar@S...]
> >Sent: 25 March 2001 23:56
> >To: ASP Databases
> >Subject: [asp_databases] Re: Creating a table
> >
> >
> >Hi there,
> >
> >It sounds like you need to define your ADO constants. Either include the
> >adovbs.inc file somehow, or include a reference to your ADO dll in your
> >global.asa with the following code:
> >
> ><GLOBAL ASA>
> > <!--METADATA TYPE="TypeLib" NAME="Microsoft ActiveX Data Objects
> >2.6 Library" UUID="{00000206-0000-0010-8000-00AA006D2EA4}" VERSION="2.6"-->
> ></GLOBAL ASA>
> >
> >You may have to change the code / GUID to reflect your version of ADO.
> >
> >Hope this helps,
> >
> >Imar
> >
> >
> >At 02:50 PM 3/24/2001 +0000, you wrote:
> > >Imar, I am joining this thread half-way through but I am trying to do
> > >exactly the same thing, create a new db table from within an existing db.
> > >I have tried your code as is in an asp page. I have just place your code
> > >and a submit button on the page. the idea is to click the button and
> > >create the db table.
> > >I am getting the following error
> > >
> > >'The application is using arguments that are of the wrong type, are out
>of
> > >acceptable range, or are in conflict with one another.
> > >
> > >/wdk/create.asp, line 28'
> > >
> > >Area Line 28 reads:
> > > With col
> > > .ParentCatalog = catDB
> > > .Type = adInteger
> > > .Name = "ID"
> > > .Properties("Autoincrement") = True
> > > End With
> > >Line 28 tblNew.Columns.Append col
> > > ' Now add the rest of the columns
> > > With tblNew
> > > .Name = "Contacts"
> > > ' Create fields and append them to the
> > >
> > >I am just trying to create a table as is specified in your code so the
> > >only thing I have changes is the path to the db. I would appreciate any
> > >help.
> > >
> > >cheers
>
>
>---
>SoftArtisans helps developers build robust, scalable Web applications!
>Excel Web reports, charts: http://www.softartisans.com/excelwriter.html
>File uploads: http://www.softartisans.com/saf.html
>Transactional file management: http://www.softartisans.com/saf1.html
>Scalability: http://www.softartisans.com/saxsession.html
>ASPstudio value pack: http://www.softartisans.com/aspstudiosuite.html
Message #11 by "Ian Richardson" <ian@i...> on Mon, 26 Mar 2001 23:44:42 +0100
|
|
Imar,
Your a star! It almost worked straight off, all I had to do was to put an
adovbs.inc file in and it worked. I am now one big happy camper, thank you
for ALL your help today.
cheers
-----Original Message-----
From: Imar Spaanjaars [mailto:Imar@S...]
Sent: 26 March 2001 21:55
To: ASP Databases
Subject: [asp_databases] Re: Creating a table
Hi Ian,
You'll need to move the METADATA tag outside the application on start
event. You are not actually storing the object or anything in the
application.
<!--METADATA TYPE="TypeLib" NAME="Microsoft ActiveX Data Objects 2.6
Library" UUID="{00000206-0000-0010-8000-00AA006D2EA4}" VERSION="2.6"-->
<script language="vbscript" runat="server">
Sub Session_OnStart
End Sub
Sub Session_OnEnd
End Sub
Sub Application_OnStart
End Sub
Sub Application_OnEnd
End Sub
</script>
(If you don' t have any code inside the events, remove it from your
global.asa file)
Next, the reason why the table is not created: you're not calling your sub.
I moved the example code to a sub to make it more reusable code. But the
sub won't be executed by itself. Try this:
Dim sDatabaseName
sDatabaseName = "C:\wdk\data\details.mdb"
' Now call the sub and pass the database name as a parameter:
CreateAccessTable(sDatabaseName)
I am pretty sure this will do the trick.
Please let me know if you got this to work.
Imar
At 09:13 PM 3/26/2001 +0100, you wrote:
>So Imar.. where were we?
>
>below is the code from the global asa and my web page
>
>I am not too aware of adox although I have downloaded and installed the
MDAC
>2.6 SDK with Jet v 4.0 sp3. I am running from a W98 desktop, PWS and Access
>2000. I also have SQL Server 7, will this code produce results if I use SQL
>7?
> cheers
>
>**********global asa************
>Sub Session_OnStart
>Session.LCID = 1057
>Session("Accepted") = 0
>End Sub
>
>Sub Session_OnEnd
>Session.Abandon
>End Sub
>
>Sub Application_OnStart
> <!--METADATA TYPE="TypeLib" NAME="Microsoft ActiveX Data Objects 2.6
>Library" UUID="{00000206-0000-0010-8000-00AA006D2EA4}" VERSION="2.6"-->
>End Sub
>
>Sub Application_OnEnd
>End Sub
>*********end global***************
>
>**********web page**************
><% @language="VBScript" %>
><%
>Dim sDatabaseName
>sDatabaseName = "C:\wdk\data\details.mdb"
>
>Sub CreateAccessTable(strDBPath)
> Dim catDB ' As ADOX.Catalog
> Set catDB = Server.CreateObject("ADOX.Catalog")
> Dim tblNew ' As ADOX.Table
> Set tblNew = Server.CreateObject("ADOX.Table")
> ' Open the catalog.
> catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> "Data Source=" & strDBPath
> ' First Create an Autonumber column, called ID. This is just for
>demonstration.
> ' I could have done this below with all the other columns as well
> Dim col ' As ADOX.Column
> Set col = Server.CreateObject("ADOX.Column")
> With col
> .ParentCatalog = catDB
> .Type = adInteger
> .Name = "ID"
> .Properties("Autoincrement") = True
> End With
> tblNew.Columns.Append col
> ' Now add the rest of the columns
> With tblNew
> .Name = "Contacts"
> ' Create fields and append them to the
> ' Columns collection of the new Table object.
> With .Columns
> .Append "aNumberColumn", adInteger
> .Append "FirstName", adVarWChar
> .Append "LastName", adVarWChar
> .Append "Phone", adVarWChar
> .Append "Notes", adLongVarWChar
> End With
> Dim adColNullable ' Is not defined in
>adovbs.inc, so do it by hand.
> ' Other option is:
> 'adColFixed with
a
>value of 1
> adColNullable = 2
> With .Columns("FirstName")
> .Attributes = adColNullable
> End With
> End With
> ' Add the new Table to the Tables collection of the database.
> catDB.Tables.Append tblNew
> Set Col = Nothing
> Set tblNew = Nothing
> Set catDB = Nothing
>End Sub
>%>
>
>
>
><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
>
>table created
>**********end web page.
Message #12 by "Ian Richardson" <ian@i...> on Mon, 26 Mar 2001 17:44:07 +0100
|
|
Imar,
below is my page code, I appreciate the time you're taking on this, I just
tried to add a table using this code. I am not too aware of adox. I have
just downloaded the MDAC 2.6 SDK and jet 4 service pack 3. Will these help?
I am working off a desktop Win 98 with PWS, does your code need to run from
NT?
Cheers
*************page code********************
<% @language="VBScript" %>
<%
Dim sDatabaseName
sDatabaseName = "C:\wdk\data\details.mdb"
Sub CreateAccessTable(strDBPath)
Dim catDB ' As ADOX.Catalog
Set catDB = Server.CreateObject("ADOX.Catalog")
Dim tblNew ' As ADOX.Table
Set tblNew = Server.CreateObject("ADOX.Table")
' Open the catalog.
catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDBPath
' First Create an Autonumber column, called ID. This is just for
demonstration.
' I could have done this below with all the other columns as well
Dim col ' As ADOX.Column
Set col = Server.CreateObject("ADOX.Column")
With col
.ParentCatalog = catDB
.Type = adInteger
.Name = "ID"
.Properties("Autoincrement") = True
End With
tblNew.Columns.Append col
' Now add the rest of the columns
With tblNew
.Name = "Contacts"
' Create fields and append them to the
' Columns collection of the new Table object.
With .Columns
.Append "aNumberColumn", adInteger
.Append "FirstName", adVarWChar
.Append "LastName", adVarWChar
.Append "Phone", adVarWChar
.Append "Notes", adLongVarWChar
End With
Dim adColNullable ' Is not defined in
adovbs.inc, so do it by hand.
' Other option is:
'adColFixed with a
value of 1
adColNullable = 2
With .Columns("FirstName")
.Attributes = adColNullable
End With
End With
' Add the new Table to the Tables collection of the database.
catDB.Tables.Append tblNew
Set Col = Nothing
Set tblNew = Nothing
Set catDB = Nothing
End Sub
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>Untitled</TITLE>
</HEAD>
<BODY>
table created
<form action="create.asp" method="POST">
<input type="Submit" name="cmdCreate" value="Create Client Table">
</form>
</BODY>
</HTML>
********end page code*************
********global asa code************
Sub Session_OnStart
Session.LCID = 1057
Session("Accepted") = 0
End Sub
Sub Session_OnEnd
Session.Abandon
End Sub
Sub Application_OnStart
<!--METADATA TYPE="TypeLib" NAME="Microsoft ActiveX Data Objects 2.6
Library" UUID="{00000206-0000-0010-8000-00AA006D2EA4}" VERSION="2.6"-->
End Sub
Sub Application_OnEnd
End Sub
*********end global asa
-----Original Message-----
From: Imar Spaanjaars [mailto:Imar@S...]
Sent: 26 March 2001 17:12
To: ASP Databases
Subject: [asp_databases] Re: Creating a table
Hi Ian,
Can you post the code for the complete page and for the bit in Global.asa??
Maybe something else is causing the problem.
Did you create complete database with ADOX or did you just try to add a
table? Make sure your user (IUSR_MachineName) has enough permissions to
write to the database
Imar
At 09:39 AM 3/26/2001 +0100, you wrote:
>Hi Imar,
>
>Thanks for the pointers, the script now appears to be working in that it
>executes, produces no error messages and reads down to my 'Success'
>message. However, I cannot find any db table in the specified db. Do you
>have any ideas why or am I missing something really obvious?
>Cheers
>
>-----Original Message-----
>From: Imar Spaanjaars [mailto:Imar@S...]
>Sent: 25 March 2001 23:56
>To: ASP Databases
>Subject: [asp_databases] Re: Creating a table
>
>
>Hi there,
>
>It sounds like you need to define your ADO constants. Either include the
>adovbs.inc file somehow, or include a reference to your ADO dll in your
>global.asa with the following code:
>
><GLOBAL ASA>
> <!--METADATA TYPE="TypeLib" NAME="Microsoft ActiveX Data Objects
>2.6 Library" UUID="{00000206-0000-0010-8000-00AA006D2EA4}" VERSION="2.6"-->
></GLOBAL ASA>
>
>You may have to change the code / GUID to reflect your version of ADO.
>
>Hope this helps,
>
>Imar
>
>
>At 02:50 PM 3/24/2001 +0000, you wrote:
> >Imar, I am joining this thread half-way through but I am trying to do
> >exactly the same thing, create a new db table from within an existing db.
> >I have tried your code as is in an asp page. I have just place your code
> >and a submit button on the page. the idea is to click the button and
> >create the db table.
> >I am getting the following error
> >
> >'The application is using arguments that are of the wrong type, are out
of
> >acceptable range, or are in conflict with one another.
> >
> >/wdk/create.asp, line 28'
> >
> >Area Line 28 reads:
> > With col
> > .ParentCatalog = catDB
> > .Type = adInteger
> > .Name = "ID"
> > .Properties("Autoincrement") = True
> > End With
> >Line 28 tblNew.Columns.Append col
> > ' Now add the rest of the columns
> > With tblNew
> > .Name = "Contacts"
> > ' Create fields and append them to the
> >
> >I am just trying to create a table as is specified in your code so the
> >only thing I have changes is the path to the db. I would appreciate any
> >help.
> >
> >cheers
|
|
 |