2
我試圖在現有的mdb數據庫中創建新表,但是使用一個變量來指定新的表名,該變量的值從輸入值設置到表單中。如果我爲新表指定名稱,但在使用變量值時失敗,則它工作正常。使用變量名創建新的mdb表
我已經看過幾篇關於使用動態sql但完全不熟悉sql的文章,我一直無法理解這些建議。任何幫助,將不勝感激。
<%
table1 = Session("tableName")
set conn = server.CreateObject ("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath ("database.mdb")
Dim strSQL
'this works with explict naming and creates a table named table1
'strSQL = "CREATE TABLE table1 (field1 int, field2 char)"
'this does not work when trying to use a variable to set the tables name
strSQL = "CREATE TABLE" & table1 & "(field1 int, field2 char)"
conn.Execute strSQL
conn.Close
%>
需要'TABLE'後面的空格。 – ZippyV