|
作者: jahson [jahson] 论坛用户 | 登录 |
各位高手,请问在做网页时,怎样插进数据库? |
地主 发表时间: 04-10-10 12:28 |
回复: tommy_he [tommy_he] 版主 | 登录 |
你先要确定是不是能用数据库 DbPath = Server.Mappath("../Database/test.mdb") strConn = "DRIVER = Microsoft Access Driver (*.mdb); DBQ=" & DbPath set conn = Server.CreateObject("ADODB.Connection") conn.Open strConn |
B1层 发表时间: 04-10-10 12:49 |
回复: ywdp [ywdp] 论坛用户 | 登录 |
能不能详细解释以下上面的代码?谢了,对网络编程刚接触,多多讨教了`~~ |
B2层 发表时间: 04-10-11 01:23 |
回复: qiezic [qiezic] | 登录 |
'SQL数据库链接(ADO) set conn = server.createobject("Adodb.connection") conn.open "Driver={SQL Server};Server=(local);Database=数据库名称;Uid=sa;Pwd=" 'Access数据库链接(ADO) dbpath = server.mappath("数据库路径") connstr = "driver={microsoft access driver (*.mdb)};dbq=" & dbpath set conn = server.createobject("adodb.connection") conn.open connstr 'Oracle数据库链接(ADO) connstring="Provider=OraOLEDB.Oracle.1;Password=pass0;Persist Security Info=True;User ID=user0;Data Source=DLA" set conn=server.createobject("ADODB.Connection") conn.open connstring conn.close '断开数据库链接 set conn=nothing '释放资源 '查询语句 set rs=server.CreateObject("ADODB.RecordSet") trySql="select * from 表名" rs.open trySql,Conn,1,1 do while not rs.eof 变量 = rs(0) 'rs(参数) 参数>=0,其中0代表第一个字段,1代表第二个字段,后 '面的依此类推就知道了! response.write 变量 ……………… rs.movenext '记录下移一条 还有rs.movefirst为移到第一条记录和rs.recordcount '为满足查询条件的记录总数 loop rs.close '断开表链接 set rs=nothing '释放资源 '添加记录语句 set rs=server.CreateObject("ADODB.RecordSet") trySql="select * from 表名" rs.open trySql,Conn,3,3 rs.addnew rs(1)=变量 ………… rs.update rs.close '断开表链接 set rs=nothing '释放资源 '修改记录语句 set rs=server.CreateObject("ADODB.RecordSet") trySql="select * from 表名 where 字段名 ="&变量 rs.open trySql,Conn,3,3 if not rs.eof then rs(1)=变量 ………… end if rs.update rs.close '断开表链接 set rs=nothing '释放资源 '删除记录语句 set rs=server.CreateObject("ADODB.RecordSet") trySql="select * from 表名 where 字段名="&变量 rs.open trySql,Conn,3,3 if not rs.eof then rs.delete end if rs.close '断开表链接 set rs=nothing |
B3层 发表时间: 04-10-11 08:41 |
回复: poemail [poemail] 论坛用户 | 登录 |
收藏中! |
B4层 发表时间: 04-10-11 18:51 |
回复: vc_java [vc_java] 论坛用户 | 登录 |
挺细的! 再补一下下! oConn.Open "Provider=MSDASQL;" & _ "Driver={SQL Server};" & _ "Server=myServerName;" & _ "Database=myDatabaseName;" & _ "Uid=myUsername;" & _ "Pwd=myPassword;" For more information, see: Microsoft OLE DB Provider for ODBC OLE DB Provider for Oracle (from Microsoft) oConn.Open "Provider=msdaora;" & _ "Data Source=MyOracleDB;" & _ "User Id=myUsername;" & _ "Password=myPassword;" For more information, see: Microsoft OLE DB Provider for Oracle OLE DB Provider for Oracle (from Oracle) For Standard Security: oConn.Open "Provider=OraOLEDB.Oracle;" & _ "Data Source=MyOracleDB;" & _ "User Id=myUsername;" & _ "Password=myPassword;" For a Trusted Connection: oConn.Open "Provider=OraOLEDB.Oracle;" & _ "Data Source=MyOracleDB;" & _ "User Id=/;" & _ "Password=;" ' Or oConn.Open "Provider=OraOLEDB.Oracle;" & _ "Data Source=MyOracleDB;" & _ "OSAuthent=1;" Note: "Data Source=" must be set to the appropriate Net8 name which is known to the naming method in use. For example, for Local Naming, it is the alias in the tnsnames.ora file; for Oracle Names, it is the Net8 Service Name. For more information, see: Connecting to an Oracle Database (Note, if you get a Logon dialog, then click Cancel, then perform a one-time free signup with Oracle's TechNet system) OLE DB Provider for Simple Provider The Microsoft OLE DB Simple Provider (OSP) allows ADO to access any data for which a provider has been written using the OLE DB Simple Provider Toolkit. Simple providers are intended to access data sources that require only fundamental OLE DB support, such as in-memory arrays or XML documents. OSP in MDAC 2.6 has been enhanced to support opening hierarchical ADO Recordsets over arbitrary XML files. These XML files may contain the ADO XML persistence schema, but it is not required. This has been implemented by connecting the OSP to the MSXML2.DLL, therefore MSXML2.DLL or newer is required. oConn.Open "Provider=MSDAOSP;" & _ "Data Source=MSXML2.DSOControl.2.6;" oRS.Open "http://WebServer/VirtualRoot/MyXMLFile.xml", oConn For more information, see: Microsoft OLE DB Simple Provider OLE DB Provider for SQL Server For Standard Security: oConn.Open "Provider=sqloledb;" & _ "Data Source=myServerName;" & _ "Initial Catalog=myDatabaseName;" & _ "User Id=myUsername;" & _ "Password=myPassword;" For a Trusted Connection: oConn.Open "Provider=sqloledb;" & _ "Data Source=myServerName;" & _ "Initial Catalog=myDatabaseName;" & _ "Integrated Security=SSPI;" To connect to a "Named Instance" (SQL Server 2000) oConn.Open "Provider=sqloledb;" & _ "Data Source=myServerName\Inst2;" & _ "Initial Catalog=myDatabaseName;" & _ "User Id=myUsername;" & _ "Password=myPassword;" To Prompt user for username and password: oConn.Provider = "sqloledb" oConn.Properties("Prompt") = adPromptAlways oConn.Open "Data Source=myServerName;" & _ "Initial Catalog=myDatabaseName;" To connect via an IP address: oConn.Open "Provider=sqloledb;" & _ "Data Source=xxx.xxx.xxx.xxx,1433;" & _ "Network Library=DBMSSOCN;" & _ "Initial Catalog=myDatabaseName;" & _ "User ID=myUsername;" & _ "Password=myPassword;" Note: - xxx.xxx.xxx.xxx is an IP address - "Network Library=DBMSSOCN" tells OLE DB to use TCP/IP rather than Named Pipes (Q238949) - 1433 is the default port number for SQL Server - You can also add "Encrypt=yes" for encryption For more information, see: Microsoft OLE DB Provider for SQL Server Remote Data Service (RDS) Connections The following examples show how to connect to a remote database using the RDS Data Control. When using the RDS DataControl's Server/SQL/Connect properties, the RDS DataControl uses the RDS DataFactory on the remote server. If you use the RDS DataControl's URL property, then the RDS DataFactory is not used at all. WARNING: The RDS DataFactory can be a major security hole if not setup and configured correctly! For more information, see RDS FAQ #24 RDS DataControl - Connect Property With the RDS default handler disabled (not recommend due to security risks): With oRdc .Server = "http://carl2" .Sql = "Select * From Authors Where State = 'CA'" .Connect = "Provider=sqloledb;" & _ "Data Source=(local);" & _ "Initial Catalog=pubs;" & _ "User Id=sa;" & _ "Password=;" .Refresh End With With the RDS default handler enabled (recommend): With oRdc .Server = "http://carl2" .Handler = "MSDFMAP.Handler" .Connect = "Data |
B5层 发表时间: 04-10-11 19:56 |
|
20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon
粤ICP备05087286号