'数据库参数设置
'-----------------------------------------------------------------------------------------------
strSQLServerName = "localhost" '服务器名称或地址
strSQLDBUserName = "sa" '数据库帐号
strSQLDBPassword = "" '数据库密码
strSQLDBName = "dbname" '数据库名称
'-----------------------------------------------------------------------------------------------
Set conn = Server.CreateObject("ADODB.Connection")
strCon = "Provider=SQLOLEDB;Server=" & strSQLServerName & ";User ID=" & strSQLDBUserName & ";Password=" & strSQLDBPassword & ";Database=" & strSQLDBName & ";" //2行写在一行上
conn.Open strCon
这样就建立了与SQL的连接.
'----------------------------------------------------------------------------------------
'从表里读出数据并显示
set RS=conn.Execute("select * from asp")
do until RS.EOF
<%= RS<"字段名">%>
............
Loop
conn.Close '关闭连接
'----------------------------------------------------------------
'保存提交的数据
strLoginID = Replace(Trim(Request("LoginID")),"'","''")
strName = Replace(Trim(Request("name")),"'","''")
strPhone = Replace(Trim(Request("phone")),"'","''")
if Request.Form("Sex1")=false then '这里好像只能用false来判断,(用true判断不起作 用,strSex总是0)
strSex = 0
else
strSex = 1
end if
'接下来向表里添加记录
strSQL="insert into asp (LoginID,Name,Phone,Sex) values ('"&strLoginID&"','"&strName&"','"&strPhone&"',"&strSex&")"
conn.Execute strSQL '注意字符串的拼凑,字符类型的要在sql语句里加单引号
'根据行数动态改变行的颜色
dim rowCount = 0
'接下来循环输出即可
rowCount=rowCount+1
if rowCount mod 2=0 then
Response.Write("")
else
Response.Write("")
end if
评论前必须登录!
注册