请教用vb.net编写的asp.net代码如何读取acess数据库 ( 积分: 100 )

  • 主题发起人 主题发起人 网络无限
  • 开始时间 开始时间

网络无限

Unregistered / Unconfirmed
GUEST, unregistred user!
我有一个数据库(ip.mdb),里面有数据表(ip),表里面有字段名为ip的字段,我让数据库里面的ip显示在标签label里面,代码如下:
<%@ Page Language=&quot;VB&quot;
ContentType=&quot;text/html&quot;
ResponseEncoding=&quot;gb2312&quot;
%>
<%@Import Namespace=&quot;System.Data&quot;%>
<%@Import Namespace=&quot;System.Data.OleDb&quot;%>
<form runat=&quot;server&quot;>
<asp:Label ID=&quot;oicq&quot;
runat=&quot;server&quot;
/>
<%
dim objConnection as OleDbConnection
dim objCommand as OleDbCommand
dim objDataReader as OleDbDataReader
objConnection=new OleDbConnection(&quot;Provider=Microsoft.Jet.OleDb.4.0;Data Source=&quot;+Server.MapPath(&quot;ip.mdb&quot;))
objCommand=new OleDbCommand(&quot;select top 1 * from ip&quot;
, objConnection)
objConnection.Open()
objDataReader=objCommand.ExecuteReader()
if objDataReader.Read then
oicq.Text=Convert.ToString(objDataReader[&quot;ip&quot;])
end if
%>
</form>
浏览时提示这句不对(oicq.Text=Convert.ToString(objDataReader[&quot;ip&quot;]))
Compiler Error Message: BC30203: Identifier expected.
后经过试验,我认为问题出在objDataReader[&quot;ip&quot;],请问问题是在这里吗,如何解决,谢谢
 
我有一个数据库(ip.mdb),里面有数据表(ip),表里面有字段名为ip的字段,我让数据库里面的ip显示在标签label里面,代码如下:
<%@ Page Language=&quot;VB&quot;
ContentType=&quot;text/html&quot;
ResponseEncoding=&quot;gb2312&quot;
%>
<%@Import Namespace=&quot;System.Data&quot;%>
<%@Import Namespace=&quot;System.Data.OleDb&quot;%>
<form runat=&quot;server&quot;>
<asp:Label ID=&quot;oicq&quot;
runat=&quot;server&quot;
/>
<%
dim objConnection as OleDbConnection
dim objCommand as OleDbCommand
dim objDataReader as OleDbDataReader
objConnection=new OleDbConnection(&quot;Provider=Microsoft.Jet.OleDb.4.0;Data Source=&quot;+Server.MapPath(&quot;ip.mdb&quot;))
objCommand=new OleDbCommand(&quot;select top 1 * from ip&quot;
, objConnection)
objConnection.Open()
objDataReader=objCommand.ExecuteReader()
if objDataReader.Read then
oicq.Text=Convert.ToString(objDataReader[&quot;ip&quot;])
end if
%>
</form>
浏览时提示这句不对(oicq.Text=Convert.ToString(objDataReader[&quot;ip&quot;]))
Compiler Error Message: BC30203: Identifier expected.
后经过试验,我认为问题出在objDataReader[&quot;ip&quot;],请问问题是在这里吗,如何解决,谢谢
 
应写成:
oicq.Text=objDataReader[&quot;ip&quot;].ToString()
 
oicq.Text=Convert.ToString(objDataReader[&quot;ip&quot;])
应该改成:
oicq.Text=CStr(objDataReader[&quot;ip&quot;])
或者比如ip字段在ip表处于第二个字段,则
oicq.Text=CStr(objDataReader(1))
 
后退
顶部