System.Data.OleDb.OleDbException: 文件名无效。
俺是新手,刚学aspx。我下面的代码哪儿出问题了呢?<%@PageLanguage="C#"Debug="true"%><%@importNamespace="Syste...
俺是新手,刚学aspx。我下面的代码哪儿出问题了呢?
<%@ Page Language="C#" Debug="true"%>
<%@ import Namespace="System.Data"%>
<%@ import Namespace="System.Data.OleDb"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
OleDbDataReader dr;
public void Page_Load(Object src, EventArgs e)
{
string MyConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+Server.MapPath(".")+"F:\\student.mdb;" ;
string strsel ="Select * from student";
OleDbConnection MyConn = new OleDbConnection(MyConnString);
OleDbCommand MyComm = new OleDbCommand(strsel,MyConn);
MyComm.Connection.Open();
dr = MyComm.ExecuteReader();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<b>演示</b>
<table border="1" style="width: 304px; height: 87px">
<tr bgcolor="#aaaadd"><td>111</td><td>222</td><td>333</td></tr>
<% while (dr.Read())
{
%>
<tr><td style="height: 23px"><%=dr["id"].ToString()%></td><td style="height: 23px"><%=dr["name"].ToString()%></td><td style="height: 23px"><%=dr["sex"].ToString()%></td></tr>
<%}
dr.Close();
%>
</table> </div>
</form>
</body>
</html>
出现的错误;
源错误:
行 12: OleDbConnection MyConn = new OleDbConnection(MyConnString);
行 13: OleDbCommand MyComm = new OleDbCommand(strsel,MyConn);
行 14: MyComm.Connection.Open();
行 15: dr = MyComm.ExecuteReader();
行 16: }
第14行 展开
<%@ Page Language="C#" Debug="true"%>
<%@ import Namespace="System.Data"%>
<%@ import Namespace="System.Data.OleDb"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
OleDbDataReader dr;
public void Page_Load(Object src, EventArgs e)
{
string MyConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+Server.MapPath(".")+"F:\\student.mdb;" ;
string strsel ="Select * from student";
OleDbConnection MyConn = new OleDbConnection(MyConnString);
OleDbCommand MyComm = new OleDbCommand(strsel,MyConn);
MyComm.Connection.Open();
dr = MyComm.ExecuteReader();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<b>演示</b>
<table border="1" style="width: 304px; height: 87px">
<tr bgcolor="#aaaadd"><td>111</td><td>222</td><td>333</td></tr>
<% while (dr.Read())
{
%>
<tr><td style="height: 23px"><%=dr["id"].ToString()%></td><td style="height: 23px"><%=dr["name"].ToString()%></td><td style="height: 23px"><%=dr["sex"].ToString()%></td></tr>
<%}
dr.Close();
%>
</table> </div>
</form>
</body>
</html>
出现的错误;
源错误:
行 12: OleDbConnection MyConn = new OleDbConnection(MyConnString);
行 13: OleDbCommand MyComm = new OleDbCommand(strsel,MyConn);
行 14: MyComm.Connection.Open();
行 15: dr = MyComm.ExecuteReader();
行 16: }
第14行 展开
展开全部
string MyConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+Server.MapPath(".")+"F:\\student.mdb;" ;
这里错了
应该这样写
string MyConnString = "Provider = Microsoft.jet.OLEDB.4.0; Data Source =" + Server.MapPath("相对路径");
Server.MapPath这个里面应该是写相对路径,他会返回服务器上的绝对路径
这里错了
应该这样写
string MyConnString = "Provider = Microsoft.jet.OLEDB.4.0; Data Source =" + Server.MapPath("相对路径");
Server.MapPath这个里面应该是写相对路径,他会返回服务器上的绝对路径
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询