‘壹’ ASp连接数据库
用的最多的就是ACCESS和sql
Server数据库,连接语句如下:
1.
ASP连接Access数据库语句
Set
Conn=Server.CreateObject("ADODB.Connection")
Connstr="DBQ="+server.mappath("www/bbs.mdb")+";DefaultDir=;DRIVER={Microsoft
AccessDriver(*.mdb)};"
Conn.Open
connstr
其中Set
Conn=Server.CreateObject("ADODB.Connection")为建立一个访问数据的对象
server.mappath("www/bbs.mdb")是告诉服务器access
数据库访问的路径
2.
ASP连接Sqlserver数据库语句
Set
conn
=
Server.CreateObject("ADODB.Connection")
conn.Open"driver={SQLServer};server=202.108.32.94;uid=wu77445;pwd=p780522;database=w
ww_panwei_com"
conn
open
其中/Set
conn
=
Server.CreateObject("ADODB.Connection")为设置一个数据库的连接对象
driver=()告诉连接的设备名是SQL-SERVER
server是连接的服务器的ip地址,Uid是指用户的用户名,pwd是指的用户的password,
database是用户数据库在服务器端的数据库的名称
‘贰’ 如何用ASP连接SQLSERVER数据库
连接方法有三种分别为通过ODBC DSN建立连接,通过oledb建立连接 通过driver建立连接三种,下面我们来看看第一种。
通过driver建立连接
代码如下
<%
Const DataBaseType=1
If DataBaseType=0 then
DBPath="/jb51/news.asp"
SqlNowString = "Now()"
ystr=true
nstr=false
suiji="rnd(id)"
Else
'如果是SQL数据库,请认真修改好以下数据库选项
DataServer = "www111cnnet" '数据库服务器IP
DataUser = "jb51net" '访问数据库用户名
DataBaseName = "jb51net" '数据库名称
DataBasePsw = "密码" '访问数据库密码
SqlNowString = "getdate()"
ystr=1
nstr=0
suiji="newid()"
End if
On Error Resume Next
If DataBaseType = 1 Then
ConnStr="driver={SQL Server};server="&dataserver&";UID="&datauser&";PWD="&databasepsw&";Database="&databasename
Else
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(DBPath)
End If
Set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnStr
If Err Then Err.Clear:Set conn = Nothing:Response.Write "数据库连接出错,请检查Conn.asp文件中的数据库参数设置。":Response.End
%>
通过driver建立连接
通过driver建立页面与数据库的连接,同样不需要创建ODBC DSN数据源,但必须知道实际的数据库文件路径或者数据源名(例如,SQLserver的数据库)。
代码如下
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open"driver={SQL Server};server=abc;DataSource=(test);uid=;pwd=;database=UserDB"
编写脚本和数据库源建立连接
ADO(ActiveX Data Objects ) 提供 Connection 对象,可以使用该对象建立和管理应用程序和 ODBC 数据库之间的连接。Connection 对象具有各种属性和方法,可以使用它们打开和关闭数据库连接。编写数据库连接脚本,首先应创建 Connection 对象的实例,接着打开数据库连接
代码如下
'********************************************************************
' 与SQL Server2000有关的连接
' 可以参照它建立您的数据库连接
'********************************************************************
'敬请注意:
'请根据情况配置StrServer,StrUid,StrSapwd,StrDbName四个参数
Dim StrServer,StrUid,StrSaPwd,StrDbName
StrServer="(local)" '数据库服务器名
StrUid="testuser" '您的登录帐号
StrSaPwd="12345" '您的登录密码
StrDbName="db_test_com" '您的数据库名称
Dim Conn '数据库连接
Dim StrDSN '数据库连接字符串
Dim Rs '命令字符串
StrDSN="driver={SQL server};server="&StrServer&";uid="&StrUid&";pwd="&StrSaPwd&";database="&StrDbName
'建立和数据库master的连接
set Conn = Server.CreateObject("ADODB.Connection")
set Rs=Server.CreateObject("ADODB.RecordSet")
Conn.Open StrDSN
‘叁’ 求一个asp与sql数据库连接的应用实例,越简单越好。
创建数据库连接对象
<%
set dxm=server.CreateObject("adodb.connection")
blm="driver=sql server;server=你计算机的IP地址;database=web;uid=sa;pwd="
dxm.open blm
%>
uid=sa;pwd= 你可以打开你的查询分析器看看他是用什么身份验证的
如果不是sa和空密码就自己设置一个用户.
dxm和blm是自己定的对象名和变量名
添加数据:
<%
set sql=server.CreateObject("adodb.recordset")
sql.open "select * from 表名",dxm,1,3 '这里是全表查询
sql.addnew
sql("字段名")=要添加的数据(如果是用表单提交就用 request.form("表单文本框名称") )
你有几个字段就添加几次(例如:sql("name")=request.from("username"))
sql.update
%>
上面是添加数据的方法,现在该查询了:
<%
set sql=server.CreateObject("adodb.recordset")
sql.open "select * from 表名",dxm,1,3 '这里是全表查询
%>
在你想要显示的地方做上<%=sql("字段名")%>就可以了.
删除:
将添加数据那里的代码改为:
<%set sql=server.CreateObject("adodb.recordset")
sql.open "select * from 表名 where 条件",dxm,1,3
sql.delete
%>
条件 就是例如name=小张 等等类似的
改:同添加一样
将添加中的sql.addnew去掉
改为:sql.update
代码如下:
<%
set sql=server.CreateObject("adodb.recordset")
sql.open "select * from 表名",dxm,1,3 '这里是全表查询
sql.update
sql("字段名")=要更改的数据(如果是用表单提交就用 request.form("表单文本框名称") )
你改几个字段就写几次(例如:sql("name")=request.from("username")
sql("sex")=request.from("sex"))
%>
这是用sql语句的对象做的,下面给你一些增、删、改、查 的代码
增:
全表添加:insert into 表名 values (值1,值2,……值n)
部分字段添加:
insert into 表名(字段1,字段2,……字段n) values(值1,值2,……值n)
删:delete from 表名 where 条件
改:update 表名 set 字段名1=新值1,字段名2=新值2,……where 条件
查:select * from (全表查询)
select * from 表名 where 条件 (带条件查询)
‘肆’ ASP怎样连接ACCESS数据库 最好给个例子
ASP连接ACCESS数据库
Dim conn,connstr
on error resume next
connstr="dbq="+server.mappath("&DataBase&")+";defaultdir=;driver={microsoft access driver (*.mdb)};"
set conn=server.createobject("adodb.connection")
conn.open connstr
sub CloseConn()
conn.close
set conn=nothing
end sub
‘伍’ ASP怎么连接SQL数据库
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data.SqlClient;//注意需要添加此句
namespaceaspnet3
{
publicpartialclassdatatest:System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
stringstrconn="server=localhost;uid=sa;pwd=longlt;database=School";
SqlConnectionconn=newSqlConnection(strconn);//创建连接
stringsql="select*fromstudents";
conn.Open();
SqlCommandcmd=newSqlCommand(sql,conn);//执行查询
Response.Write("连接成功");
SqlDataReaderdr=cmd.ExecuteReader();//查询结果
if(dr.Read())
{
//利用dr[索引]对数据库表进行操作,dr[]返回object;
//可以用字段做索引,也可用列号0,1..做索引
Response.Write(dr[0].ToString()+"<br>");
}
//this.Lab.Text="suc";
}
}
}
在上面的例子中,我们连接了一个sa下的School数据库,并查询了其中students字段的内容。
连接数据库分为三个步骤:先定义连接信息,再创建一个连接,最后打开连接
stringstrconn="server=localhost;uid=sa;pwd=longlt;database=School";//在这一段修改数据库的信息
SqlConnectionconn=newSqlConnection(strconn);//创建连接
conn.Open();//打开连接
‘陆’ 如何用asp连接SQL Server 数据库
<%
Dim mode
mode=request.form("text4")
if mode=1 then
name=request.form("text1")
age=request.form("text2")
addr=request.form("text3")
if not isnumeric(age) then response.write "age must be number!<a href=javascript:history.go(-1)>try again</a>":response.end
age=clng(age)
end if
"********************************************************************
" 与SQL Server2000有关的连接
" 可以参照它建立您的数据库连接
"********************************************************************
"敬请注意:
"请根据情况配置StrServer,StrUid,StrSapwd,StrDbName四个参数
Dim StrServer,StrUid,StrSaPwd,StrDbName
StrServer="(local)" "数据库服务器名
StrUid="testuser" "您的登录帐号
StrSaPwd="12345" "您的登录密码
StrDbName="db_test_com" "您的数据库名称
Dim Conn "数据库连接
Dim StrDSN "数据库连接字符串
Dim Rs "命令字符串
StrDSN="driver={SQL server};server="&StrServer&";uid="&StrUid&";pwd="&StrSaPwd&";database="&StrDbName
"建立和数据库master的连接
set Conn = Server.CreateObject("ADODB.Connection")
set Rs=Server.CreateObject("ADODB.RecordSet")
Conn.Open StrDSN
"********************************************************************
"********************************************************************
Dim strsql
"********************************************************************
" 读数据库的相关操作
sub readdb()
strsql="select * from test"
rs.open strsql,conn,1,1
if rs.EOF then response.write "no record at all":exit sub
response.write "<table border=1>"
response.write "<tr>"
for i=0 to rs.Fields.Count-1
response.write "<td><font color=blue>"&rs.Fields(i).Name&"</font></td>"
next
response.write "</tr>"
while not rs.EOF
response.write "<tr>"
for i=0 to rs.Fields.Count-1
response.write "<td>"&rs.Fields(i).Value&"</td>"
next
response.write "</tr>"
rs.MoveNext
wend
response.write "</table>"
rs.Close
end sub
"********************************************************************
"********************************************************************
" 写数据库的相关操作
sub insertdata()
strsql="INSERT INTO test(name,age,addr) VALUES(""&name&"","&age&",""&addr&"")"
rs.Open strsql,conn,1,3
end sub
"********************************************************************
if mode=1 then
call insertdata()
response.write "insert ok!"
elseif mode=2 then
call readdb()
end if
"释放数据库连接对象
set rs=nothing
set conn=nothing
%>
<HTML>
<HEAD>
<TITLE></TITLE>
<script language=javascript>
function clickit(flag){
var form1=document.form2
form1.text4.value=flag;
if (flag==1){
if (form1.text1.value==""){
alert("name cant empty!");
return false;
}
if (form1.text2.value==""){
alert("age cant empty!");
return false;
}
if (form1.text3.value==""){
alert("addr cant empty!");
return false;
}
}
form1.submit();
return true;
}
</script>
</HEAD>
<BODY>
<form method=post name=form2>
name:<INPUT type="text" id=text1 name=text1 size=12>
age:<INPUT type="text" id=text2 name=text2 size=12>
city:<INPUT type="text" id=text3 name=text3 size=12><br>
<INPUT type="hidden" id=text4 name=text4>
<INPUT type="button" value="write" id=button1 name=button1 onclick="clickit(1)">
<INPUT type="button" value="read" id=button2 name=button2 onclick="clickit(2)">
</form>
</BODY>
</HTML>
‘柒’ ASP 怎么连接SQL数据库
ASP与SQL数据库连接语句具体如下:
Set conn = Server.CreateObject("ADODB.Connection")
connstr = "provider=Sqloledb;server=服务器名;uid=用户名;pwd=密码;database=数据库名"
conn.Open connstr
If Err Then
err.Clear
Set conn = Nothing
Response.Write "数据库连接出错,请检查连接字串"
Response.End
(7)asp连接数据库实例扩展阅读:
SQL常用命令使用方法:
(1) 数据记录筛选:
sql="select * from 数据表 where 字段名=字段值 order by 字段名 "
sql="select * from 数据表 where 字段名 like ‘%字段值%‘ order by 字段名 "
sql="select top 10 * from 数据表 where 字段名 order by 字段名 "
sql="select * from 数据表 where 字段名 in (‘值1‘,‘值2‘,‘值3‘)"
sql="select * from 数据表 where 字段名 between 值1 and 值2"
(2) 更新数据记录:
sql="update 数据表 set 字段名=字段值 where 条件表达式"
sql="update 数据表 set 字段1=值1,字段2=值2 …… 字段n=值n where 条件表达式"
(3) 删除数据记录:
sql="delete from 数据表 where 条件表达式"
sql="delete from 数据表" (将数据表所有记录删除)
‘捌’ 求asp。net连接数据库的最最简单的例子
string MyConn = "Initial Catalog=Northwind;Data Source="您服务器名称";User ID=账户名 Password=密码";//定义数据库连接参数
SqlConnection MyConnection = new SqlConnection();//定义一个数据连接实例
MyConnection.ConnectionString = MyConn;
try
{
MyConnection.Open();
Response.Write("连接数据库成功!");
}
catch (Exception e)
{
Response.Write(e.Message);
}
finally
{
MyConnection.Close();
}
‘玖’ asp 数据库连接,读取,写入,修改的简单例子
Makes a qualified network management key to lie in is the person, is asolid person Although said: " Does was inferior to looks, lookswas inferior to said, said is inferior to the dawdle, but I thought isthe person is most important, 1st, makes the network management, mainly is maintains theserver, the terminal, the customer end and network synthesis wiring aswell as network planning and so on, perhaps just started to think workload very big, mood very bothersome, pressure very big, was the workis impetuous for others' feeling, passes through pondering over whicha period of time working practice and lived, was allowed to feel themain question was oneself has not learned to adjust oneself, adjustedown life appeal, in the nature work question also meets You Rener tosolve, and has understood the life happiness. 2nd, is a qualified network administrator most to need to grasp anetwork reasonable plan, dynamic management, static surveillance,long-distance debugging maintenance, including network topology,network agreement transmission step, network flow control, QOs, eachkind of agreement disposition and reasonable use. Network administrator itself is the technical post, therefore thetechnology must first. As for any technology most important, that mustthink each unit the demand, the simple possibility so long asconnected and can the exchange visits be good. The complex networkpossibly was several people even more people's matter, had thedivision of labor and the cooperation, various person of maintenanceand the study direction is dissimilar. The common middle and smallscale unit all does not suppose the network management, because thecomputer are few, does not need specially to set up sentries, hasoutside the question to ask the person to go. Surpasses 20 unitspossibly to have to suppose the special network management or theconcurrent job network management, such unit's network management hasthe IT various aspects on the request the knowledge, jumps over GuangYuehao. Two: The enterprise network management needs to grasp the skill makesnetwork management nearly anything to need to know that a spot, notnecessarily must fine, certainly you also must have own strong point. 1. Made the system is the most basic request, from 98 to 2003, all hadto be able to play from unix to linux, fine (this difficulty systemvery was not necessarily all high) 2. Can maintain the PC hardware and the printer (to spurts inkfrom needle type to arrive laser), if this part does is not good,possibly every day suffices your busy morning 3. Meets the MAIL service and the customer end disposition and themanagement, mainly has Exchange, Imail, Qmail, Sendmail and so on, thepresent enterprise all has own MAIL, moreover occupies the status highis absolutely not allow to neglect 4. To the windows/*nix system must know the common servicedisposition, most basic certainly is DHCP (DHCPD), DNS (BIND), IIS(APACHE), FTP (WUFTPD/VSFTPD), AD (SAMBA), WINS and so on, if theseall not too understand, hurries ruthlessly to make up Otherwise didnot must go 5. The database at least needs to understand SQL SERVER with MYSQL, ifmeets ORACLE/SYBASE/DB2/INFORMIX, that wages definitely can be high10% (ha-ha a little exaggerates, if these can, but also did not makeDBA to go?) 6. Certainly wants to the switchboard and the router simpleestablishment and the management, otherwise only could go to the smallbusiness (mainly is CISCO, China is 3COM, north electricity, certainlyto TP-LINK, the D-LINK low end equipment also had to be familiarwith). 7. The familiar synthesis wiring technology (at least knew howmakes 568A/568B), the optical fiber technology also needs slightly tounderstand 12, if you respond to a call for recruits is the factoryspeech, the workshop often can pull the optical fiber with theworkshop between 8. Must know how plans the network, enhances the network the stability(to be most important) as far as possible, security and use factorand so on 9. Can write the script, was not effective is windows or *nix, thescript often can twice the result with half the effort cause yourworking efficiency (to assemble language and so on /C has beenbetter). 10. Must know how the fast security backup with does restorethe data 11. To technology and so on proxy firewall 杀毒 must be familiar,otherwise which day was your network completely paralysed has notknown our matter The 12.WLAN technology also must grasp as soon as possible, this is atendency, the very many enterprises' partial networks all melted intoit 13. To turns on the net technology to have to be familiar, at leastmust know ADSL, ISDN, FTTX, FR, how DDN is a matter 14. Certainly some companies hire when the manager requests you tomeet ASP, PHOTOSHOP, DW and so on, they mainly are the website routinemaintenance 15. Must have a clear understanding to the entire network model andthe overhead construction, at least must know the level, theagreement, the connection, the service and so on knows, if can gnawthoroughly the TCP/IP agreement these three volumes book, then youwere allowed to start the cow 16. Has a clear understanding to the ERP system 17. Most important, also is decided the destiny the matter, needs tolearn " Enres " Small does not enre then the chaotic bigstratagem, this speech is very appropriate to the network management