|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Creating a database table using SQL CREATE TABLE
<i><b>Originally posted by : Aileen (aileenfarrell@hotmail.com)</b></i><br />Hi,<br />I am trying to create the tables in my database using ASP. I know the syntax of the CREATE TABLE and it works fine.<br /><br />Dim strSQL<br />strSQL = "CREATE TABLE test (name varchar(50),age int)"<br />conn.Execute strSQL<br /><br />However I want the user to enter the name of the table and the value will then be passed to this page. When I try to create the table using the value the user has entered I get a syntax error.<br /><br />Here is the code.<br /><br />Dim Connect, Info1, strconn, ModuleCode, rs<br />ModuleCode = request("ModuleCode")<br /><br />strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("students.mdb")<br />Set Connect = Server.CreateObject("ADODB.Connection") <br />Connect.open strconn<br />set rs = server.createobject("adodb.recordset")<br />Info1 = "CREATE TABLE" & ModuleCode & "(name varchar(50), age int)"<br />rs.open Info1, strconn<br />Connect.close<br />Set Connect = nothing<br /><br />The error is in the CREATE TABLE statement. <br />Anyone have any ideas?<br />
|
|
#2
|
|||
|
|||
|
<i><b>Originally posted by : </b></i><br /><br /><br /><br />------------<br />Aileen at 4/11/2001 4:31:26 AM<br /><br />Hi,<br />I am trying to create the tables in my database using ASP. I know the syntax of the CREATE TABLE and it works fine.<br /><br />Dim strSQL<br />strSQL = "CREATE TABLE test (name varchar(50),age int)"<br />conn.Execute strSQL<br /><br />However I want the user to enter the name of the table and the value will then be passed to this page. When I try to create the table using the value the user has entered I get a syntax error.<br /><br />Here is the code.<br /><br />Dim Connect, Info1, strconn, ModuleCode, rs<br />ModuleCode = request("ModuleCode")<br /><br />strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("students.mdb")<br />Set Connect = Server.CreateObject("ADODB.Connection") <br />Connect.open strconn<br />set rs = server.createobject("adodb.recordset")<br />Info1 = "CREATE TABLE" & ModuleCode & "(name varchar(50), age int)"<br />rs.open Info1, strconn<br />Connect.close<br />Set Connect = nothing<br /><br />The error is in the CREATE TABLE statement. <br />Anyone have any ideas?<br /><br />You will probably scream when you see what the problem is. You need white space between TABLE, ModuleCode, and the field list. Change it to:<br /><br />Info1 = "CREATE TABLE " & ModuleCode & " (name varchar(50), age int)"<br /><br />It works that way.<br /><br /><br />
|
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Creating a database table using SQL CREATE TABLE |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|