|
|
Terms of Agreement:
By using this article, you agree to the following terms...
1) You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame.
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description. |
This is the first of 2 Pages you will need...
<html>
<body>
<Form Name="Form" Type="Submit" Method="Post" Action="dynamic2.asp">
<%
<!--~----- Dim Your Variables -----~-->
Dim MyConn, SQL, RS, i
<!--~----- Create the Connection and Open the Connection to the Database
-----~-->
<!--~----- This Will Connect to a MS-SQL Database
-----~-->
<!--~----- To Connect to an Access Database Replace the Bottom 3 Lines of Code with either...
-----~-->
<!--~----- MyConn.Open "Driver={Microsoft Access Driver
(*.mdb)}; -----~-->
<!--~----- DBQ=C:\Databases\demo.mdb"
-----~-->
<!--~----- or
-----~-->
<!--~----- MyConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data
-----~-->
<!--~----- Source=C:\Databases\demo.mdb"
-----~-->
<!--~----- or
-----~-->
<!--~----- MyConn.Open DSN_Name
-----~-->
Set MyConn=Server.CreateObject("ADODB.Connection")
Myconn.ConnectionString = "Provider=SQLOLEDB; Data
Source=Your SQL Server; Initial Catalog=Your
Database; User ID=Your
Login; Password=Your
Password"
Myconn.open
<!--~-----
Wriye your SQL statement -----~-->
<!--~----- In this case we have 2 SQL
statements because I have a different value for my form fields other than its
name -----~-->
<!--~----- If your checkbox/text field
will have the same name and value you can safely remove from "SQL1 =
"Select" down
-----~-->
SQL = "Select Column
Name(s) in your Database that holds values that will become the checkbox/textfield
name From Your
Table Name"
Set RS = MyConn.Execute(SQL)
SQL1 = "Select Column
Name in your Database that holds values that will become the checkbox/textfield
value From Your
Table Name"
Set RS1 = MyConn.Execute(SQL1)
<!--~----- Read All of the Records with EOF
-----~-->
While not RS.EOF
<!--~-----
Build Your Checkboxs -----~-->
<!--~----- You Can Also Build Text Fields by Modifying the Second Line to Read
-----~-->
<!--~----- Response.Write rs.fields(intCol).Value & ": <input type=Text size=15 name=" & rs.fields(intCol).Value & "><br>" & vbcrlf
-----~-->
<!--~----- If you want the checkboxs or text fields to display column names instead of data values replace any .Value with .Name
-----~-->
<!--~----- Example
-----~-->
<!--~----- Response.Write rs.fields(intCol).Name & ": <input type=checkbox name=" & rs.fields(intCol).Name & " value=" & rs.fields(intCol).Name & "><br>" & vbcrlf
-----~-->
<!--~----- Also, if your SQL select
statement only had one line (same name/value for checkbox/textfields) the
following lines of code would read... -----~-->
<!--~----- For i = 0 to RS.fields.count
- 1
-----~-->
<!--~----- Response.Write
RS.fields(i).Value
& ":<input type=checkbox name='"
& RS.fields(i).Value
& "' value="
& RS.fields(i).Value
& "><br>"
& vbcrlf
-----~-->
<!--~----- RS.MoveNext
-----~-->
For i =
0 to RS.fields.count and RS1.fields.count
- 1
Response.Write RS.fields(i).Value
& ":<input type=checkbox name='"
& RS.fields(i).Value
& "' value="
& RS1.fields(i).Value
& "><br>"
& vbcrlf
RS.MoveNext
RS1.MoveNext
Next
Wend
RS.Close
RS1.Close
MyConn.Close
Set RS = Nothing
Set RS1 =
Nothing
Set MyConn = Nothing
%>
<br>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
Name
this page dynamic1.asp
Now
we create the page that will insert our data into your database
<html>
<body>
<%
Dim MyConn, MySQL, rs, i
Set MyConn=Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
MyConn = "Provider=SQLOLEDB; Data Source=Your
SQL Server; Initial Catalog=Your
Database; User ID=Your
SQL Login; Password=Your
Password"
MYSQL = "SELECT Column
Name you want data entered into FROM
Your Table Name"
rs.Open MySQL, MyConn, 1, 3
%>
<%
for i = 1 to
Request.form.count -1
rs.addnew
rs.Fields("Column
Name you want data entered into") = Request.form(i)
Next
rs.update
Response.Write "Thank
you"
%>
</body>
</html>
Name this page
dynamic2.asp
Vote
for me if you find this useful, let me know if you need any help with the
code!!!
| |
Download article
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzipto decompress it.
Virus note:All files are scanned once-a-day by Planet Source Code for viruses,but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE: 1)Re-scan downloaded files using your personal virus checker before using it. 2)NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com
|
Terms of Agreement:
By using this article, you agree to the following terms...
1) You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame.
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description. |
|
Report Bad Submission |
|
|
Your Vote! |
See Voting Log |
|
Other User Comments |
3/22/2001 4:50:59 AM:Kayhan Tanriseven very useful code you have!! thanks for
submitting!
|
3/22/2001 6:32:30 AM:Rax nice clean code at last :/
|
3/22/2001 8:06:04 PM:May This is very useful. I'm an asp
student. I couldn't get your demo.mdb.
Also I did not understand all the code.
How can I call this dynamic_form.asp,
and how it works. Would you like tell
me more about this function page.
|
3/23/2001 1:18:57 AM:Lorie Perrish Excellent code, I have been looking for
something that does this for a long
time!!
|
3/23/2001 10:57:19 AM:Doug Gaede Do you have an example database for use
with this code?
|
3/28/2001 12:51:04 PM:wicked what you mean ..
|
3/28/2001 12:51:28 PM:WICKED what you mean ..
wow can't believe
this is not out there
already you can
use this same coding for oracle ,sql or
even in a email
I been offering
fastemailer.asp for along time that
does this.
wow just cant believe this
wasn` t out there already.
anyway nice
job for posting it for others.Guess I
goes to show you can never realy be
sure of whats posted.
|
4/3/2001 8:18:05 AM:africa Hi,
Your code did wonders for me and
I'd give it 5 out of 5 any day!
Please
keep sending more of your new code and
keep vbscript/asp alive!!!!
|
4/7/2001 8:13:11 PM:John Can you show me how to make your
dynamic code work with 60 dropdown
box... I am new to ASP.. Thanks
My
e-mail: jhmai@eudoramail.com
|
8/15/2001 3:44:57 PM:SVM Hey, sorry to bother you, but is there
a way to use this code to submit a form
remotely?
|
10/11/2001 6:12:51 PM:RLF Where can you get the Demo.mdb. It was
not in the download
|
10/31/2001 5:31:41 PM:yogi This code is very useful. But, can we
add validations or business rules
dynamically ?
|
|
Add Your Feedback! |
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.
NOTICE: The author of this article has been kind enough to share it with you. If you have a criticism, please state it politely or it will be deleted.
For feedback not related to this particular article, please click here. |
|