|
-
Dec 12th, 2005, 08:44 PM
#1
Thread Starter
Hyperactive Member
How to make an SQL test site in ASP (im getting there)
I want to make a .ASP site where i can test *ANY* SQL statement towards an MDB (.mdb database)
So far i've made a new empty DB called: skriv.mdb
then i try to use the following code to send SQL commands to the DB
But my problem is that any results from the DB is not displayed back to me..
So if i do a: SELECT * FROM sometable; then i wont get the output back to me, so i need help to archeive this,..
Simply make an .ASP that can perform ANY sql-statement towards an DB..
So far i have this, which writes to the DB, but doesnt always work correctly
(It has problems opening/closing the connection, and NO errortrapping)
Please try to put together a working example..Thanks anyway !!
VB Code:
<HTML>
<BODY>
<center>
<B>SQL Query Testing</B><br><br>
EXAMPLES:<br>
create table tabell1 (data1 char(100),data2 char(100)); <br>
insert into tabell1 (data1,data2) values ('tekst1','tekst2'); <br>
select data1,data2 from tabell1; <br>
select * from tabell1; <br>
<br><br>
<font color="red">Skriv til database:</font>
<FORM METHOD="post" ACTION="skriv.asp?Actionvar=sql">
SQL: <INPUT TYPE="text" NAME="sql1"><BR>
<INPUT TYPE="hidden" NAME="flag" VALUE="2">
<INPUT TYPE="submit" VALUE="Utfør SQL">
</FORM>
<%
Actionvar=Request.QueryString("actionvar") '''gets the ActionVariable..
'''Setup the connection to the database
Set conn = server.createobject("adodb.connection")
DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
DSNtemp=dsntemp & "DBQ=" & server.mappath("skriv.mdb")
conn.Open DSNtemp
'''Check the querystring to decide what to do next, getting the flag..
IF Actionvar="sql" THEN
IF Len(TRIM(request.form("flag"))) = 0 THEN
%>
<%
'''if flag was set, means that a search string has been inputted, and its time to search the DB..
ELSEIF Request.Form("flag")="2" THEN
SQLstmt = SQLstmt & request.form("sql1")
%>
<%
'''Run the SQL statement at the DB, to perform the search..
conn.execute(SQLstmt)
Response.Write SQLstmt '''debugging.. to see what we runned at the DB..
END IF
end if
'''Close the DB connection..
conn.Close
Set conn = nothing
Set SQLstmt = nothing
%>
<!-- need code here to show the search results -->
</BODY>
</HTML>
***************
Please use [highlight=vb] ..your code.. [/highlight] when posting code!
When you have received the working answer to your question,
please mark it as *SOLVED* + Your Questions Title ...using your Thread's Tool menu.
Also try to point out what answer made it work for you, or edit your first post to contain a quote of the correct answer...
Please Answer All Questions With Working Code Examples...
My Unfinished Projects and My working Programs
***************
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|