Showing posts with label ASP page with database handling. Show all posts
Showing posts with label ASP page with database handling. Show all posts

Monday, March 23, 2009

ASP page with database handling

ASP page with database handling

Here is an Sample Example Which Handles MYSQL 5.0 DataBase with .Net

[code]
<%
//This page will be refreshed with each access!
Response.Expires=-1
%>


<%
//create connection object
set con=server.createobject("adodb.connection")
//Conection String and open the connection
call con.open("provider=msdasql;driver={Mysql};server=mysqlServerName;uid=username;pwd=password;database=dbnsme;")
//For Select Query Execution
set rs=con.execute("select * from tablename )
//displaying the records in a table format
//loop till rs has records
while not rs.eof
response.write("<tr><td>" & rs.fields(0) & "</td><td>" & rs.fields(1) & "</td></tr>")
rs.movenext
wend
rs.close()
response.write("</table>")


//Update Process


//update query
//a will contain how mny records are modified
con.execute("Upadte Query goes here"),a
response.write(a & " records updated")
//response.write("Done")



//Insert Process


//insert query
con.execute("insert into RegClLog (SrNo,ProdKey,ClDtTm) values('"& request.form("hidSrno") &"','"& request.form("hidResult") &"','"& request.form("hidClDtTym") &"') "),a
response.write(a & " records Inserted")

//close connection
con.Close()
%>

<html>
<head></head>
<body>
<form action="#" method="post">
Any HTML CODE here will run perfectly. to display the page

</form>
</body>
</html>


//Trapping Errors in ASP.
//This will get the last error occurred.
<%
dim objErr
set objErr=Server.GetLastError()
response.write("ASPCode=" & objErr.ASPCode)
response.write("
")
response.write("ASPDescription=" & objErr.ASPDescription)
response.write("
")
response.write("Category=" & objErr.Category)
response.write("
")
response.write("Column=" & objErr.Column)
response.write("
")
response.write("Description=" & objErr.Description)
response.write("
")
response.write("File=" & objErr.File)
response.write("
")
response.write("Line=" & objErr.Line)
response.write("
")
response.write("Number=" & objErr.Number)
response.write("
")
response.write("Source=" & objErr.Source)
%>

[/code]


Thanks and Regards
Meetu Choudhary
Founder: http://www.msdotnetmentor.com

Subscribe via email

Enter your email address:

Delivered by FeedBurner

MSDotnetMentor

MSDotnetMentor My Website http://msdotnetmentor.com