asp中如何读取sqlserver数据库中的数据
展开全部
<%
SET Conn=Server.CreateObject("ADODB.Connection")
Dim i,j,Sql
Set rt=Server.CreateObject("ADODB.Recordset")
'Conn.Open "Server=IP地址;Provider=sqloledb;Database=库名称;UID=用户名;PWD=密码;"
Conn.Open "Server=192.168.1.1;Provider=sqloledb;Database=mysql;UID=sa;PWD=mysql;"
%>
<table bordercolor="#808000" border="1" cellspacing="0" bgcolor="#EEEEEE">
<%' 读SqlServer库中的表名:
Set rs=Conn.OpenSchema(20)
While not rs.EOF
if rs(3)="TABLE" then
'response.write(rs(2)&"<br>")'表的类型
'Response.Write("所在数据库名:" & rs(0) )
'Response.Write("所有者:" & rs(1) )
'Response.Write("表 名:" & rs(2) &"<br>" )
%>
<tr>
<td><%=rs(2)%></td>
<%
'这样,知道表名了,现在再来看看怎么对表的字段进行操作。假设:其中数据库中有表:[admin] 获取该表的所有字段名:
x="[admin]"
rt.open"select * from "&rs(2)&" where 1<>1",conn,1,3
j=rt.Fields.count
For i=0 to (j-1)
'Response.Write("第" & i+1 & "个字段名:" & rt.Fields(i).Name & "<br><br>")
response.write("<td>"&rt(i).name)
Next
rt.close
end if
rs.MoveNext
Wend
%>
</table>
展开全部
dim conn,connstr,rs,sql
set conn = Server.CreateObject("Adodb.Connection")
connstr = "Provider=SQLOLEDB;data source=127.0.0.1;initial catalog=DBname;uid=username;pwd=password"
conn.open connstr
set rs = Server.CreateObject("Adodb.RecordSet")
sql = "select id from table"
rs.open sql,conn,1,1
if not rs.eof
response.write "ID为:" & rs("id")
end if
rs.close
conn.close
set conn=nothing
set conn = Server.CreateObject("Adodb.Connection")
connstr = "Provider=SQLOLEDB;data source=127.0.0.1;initial catalog=DBname;uid=username;pwd=password"
conn.open connstr
set rs = Server.CreateObject("Adodb.RecordSet")
sql = "select id from table"
rs.open sql,conn,1,1
if not rs.eof
response.write "ID为:" & rs("id")
end if
rs.close
conn.close
set conn=nothing
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
dim conn,connstr,rs,sql
set conn = Server.CreateObject("Adodb.Connection")
connstr = "Provider=SQLOLEDB;data source=127.0.0.1;initial catalog=DBname;uid=username;pwd=password"
conn.open connstr
set rs = Server.CreateObject("Adodb.RecordSet")
sql = "select id from table"
rs.open sql,conn,1,1
if not rs.eof
response.write "ID为:" & rs("id")
end if
rs.close
conn.close
set conn=nothing
set conn = Server.CreateObject("Adodb.Connection")
connstr = "Provider=SQLOLEDB;data source=127.0.0.1;initial catalog=DBname;uid=username;pwd=password"
conn.open connstr
set rs = Server.CreateObject("Adodb.RecordSet")
sql = "select id from table"
rs.open sql,conn,1,1
if not rs.eof
response.write "ID为:" & rs("id")
end if
rs.close
conn.close
set conn=nothing
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
想学就从头学,想用就花钱买,不想学就别学
100元
100元
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询