ASP database Operation method

Source: Internet
Author: User

First, you must use the Open database method:

<%dim objconn,objconnstrset objconn=server.createobject ("adodb.connection") objconnstr= "provider= Microsoft.jet.oledb.4.0;data source= "& Server.MapPath (" Data/data.mdb ") objConn.Open objconnstr%>

1. Adding database Tables

<%dim sqlsql= "Create Table Colin (ID counter primary key,company text,addr TEXT,DEP text,contacts text,phone Text,casen Ame Text,caseid int,qs_inf text,qs_wt text,isdel bit,createtime datetime) "objConn.Execute (SQL) objconn. Closeresponse.write ("Add Complete")%>

2. query table field

<%dim Sql,rs1set Rs1=server. CreateObject ("Adodb.recordset") sql= "SELECT top 1 * from C_questionnaire" Rs1.open sql,objconn,1,2for i=0 to Rs1.fields.count-1t=rs1.fields (i). Nameresponse. Write (t& "<br/>") next%>

  

3. Add Table field

<%dim sqlsql= "ALTER TABLE semi_actor add column news_id int" objconn.execute (SQL)%>

  

4. Modify table field type

<%dim sqlsql= "ALTER TABLE exhi ALTER COLUMN EXHI_IMG text ($)" objConn.Execute (SQL)%>

  

5. Adding data to a database table

<%dim A,b,c,da=1b=2c=3d=4dim rs,sqlset rs=server. CreateObject ("Adodb.recordset") sql= "SELECT * from Colin" Rs.Open Sql,objconn,1,2rs.addnew () rs ("a") =a        rs ("b") = BRS ("C") =crs ("D") =drs ("Createtime") =now () rs.update () rs.closeresponse.Write ("<script language= ' JavaScript ' >alert (' You have successfully submitted form ') </script> "%>

6. Delete database table data

<%dim sqlsql= "Delete from branch where id=" 5 "and Isdel=true" Objconn1.execute (SQL) response. Redirect ("adminbranch.asp")%>

  

7. Querying and listing database table data

<%dim Rspic,sqlpicset Rspic=server. CreateObject ("Adodb.recordset") sqlpic= "SELECT * from Colin ORDER BY createtime Desc" Rspic.open sqlpic,objconn,0,1if not Rspic.eof Thendo While not rspic.eof%><tr><td align= "center" ><%=rspic ("a")%></td><td align= "Center" ><%=rspic ("B")%></td><td align= "Center" ><%=rspic ("C")%></td>< TD align= "Center" ><%=rspic ("D")%></td></tr> <%rspic.movenextloop%><%end if%>

Finish

ASP database Operation method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.