admin
06-04-2003, 04:25 PM
This will allow you to update your field in a table from a form.
The form allows you to input the table you wish to update and the field you wish to add with a text type field and a character limit of 15. The field can also be left null so if no data is input then there will not be any error.
---Form--
<html>
<head>
<title>Add Field</title>
</head>
<body>
<br><br>
<form method="post" action="doaddfld.asp">
Enter Table Name <input type="text" name="tbl">
<br>
Enter Field Name <input type="text" name="afld">
<br>
<input type="submit" name="submit" value="create field">
<br><br>
<br><br>
</form>
</body>
</html>
---Connection String (doaddfld.asp)---
<%
Dim SQL
Dim MyConn
Dim RS
Set MyConn = Server.CreateObject ("ADODB.Connection")
Set RS = Server.CreateObject ("ADODB.Recordset")
MyConn.Open "insert DSN here or driver with db location"
'add field sql string
SQL="ALTER TABLE " & request.form("tbl") & " ADD " _
& request.form("afld") & " varchar(30)"
'execute sql
set RS=MyConn.execute(SQL)
'clean up
MyConn.close
set MyConn=Nothing
'confirm creation
response.write "Field created"
%>
By Jim Losi
The form allows you to input the table you wish to update and the field you wish to add with a text type field and a character limit of 15. The field can also be left null so if no data is input then there will not be any error.
---Form--
<html>
<head>
<title>Add Field</title>
</head>
<body>
<br><br>
<form method="post" action="doaddfld.asp">
Enter Table Name <input type="text" name="tbl">
<br>
Enter Field Name <input type="text" name="afld">
<br>
<input type="submit" name="submit" value="create field">
<br><br>
<br><br>
</form>
</body>
</html>
---Connection String (doaddfld.asp)---
<%
Dim SQL
Dim MyConn
Dim RS
Set MyConn = Server.CreateObject ("ADODB.Connection")
Set RS = Server.CreateObject ("ADODB.Recordset")
MyConn.Open "insert DSN here or driver with db location"
'add field sql string
SQL="ALTER TABLE " & request.form("tbl") & " ADD " _
& request.form("afld") & " varchar(30)"
'execute sql
set RS=MyConn.execute(SQL)
'clean up
MyConn.close
set MyConn=Nothing
'confirm creation
response.write "Field created"
%>
By Jim Losi