using System.Data.SqlClient;
改成using System.Data.Oledb; SqlConnection = oledbConnectionSqlCommand = oledbCommand
改成using System.Data.Oledb; SqlConnection = oledbConnectionSqlCommand = oledbCommand
解决方案 »
- 删除主表同时删除子表数据
- 如何上传本地MSSQL2005数据库到服务器
- detailsView在insert状态下找不到控件
- 高分盼高手解答,客户重装系统后,IE不能实现页面跳转了,该怎么办?分不够可加
- 新建ASP.NET项目不成功!提示“尝试创建Web项目或打开位于URL“http://localhost/web1”的Web项目时,Web服务器报告了以下错误。“http:/
- 值得想想:如何在网页中用链接去触发一个事件?
- 简单小问题,错误提示的意思?
- 求求大家,帮帮我吧.急死我了!!!!! 如何实现:动态地生成DataGrid,动态添加TemplateColumn,再在TemplateColumn动态添加Textbox,并binding.
- 一下代码提示 不是每个路径都有返回值,是怎么回事啊?
- 终于有两个小三角,散分!!
- 关于PKCS7
- ~~~~~~[大家来看看]asp比asp.net快很多。什么原因?asp.net还有优势吗?
Imports System.Data.OleDbPartial Class _Default
Inherits System.Web.UI.Page Private Sub page_load(ByVal sender As System.Object, ByVal e As EventArgs)
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim con As New OleDbConnection
con.ConnectionString = "provider = Microsoft.Jet.OLEDB.4.0;DATA Source=" & Server.MapPath("tzdatabase.mdb")
con.Open()
end sub
以上是数据连接字符串,你替换一下就可以了.
Con = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="**.mdb";Persist Security Info=False"
using System.Data.OleDb; 连接代码:
string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
strConnection += HttpContext.Current.Server.MapPath("DataName.mdb");
OleDbConnection accessConn = new OleDbConnection(strConnection);using System.Data.OleDb;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
try
{
string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
strConnection += HttpContext.Current.Server.MapPath("DataName.mdb");
OleDbConnection conn = new OleDbConnection(strConnection);
conn.Open();
OledbCommand cmd = new OledbCommand("select * from dl",conn);
OledbDataReader dr = cmd.ExecuteReader();
if (dr.Read())
Response.Write(dr["name"]);
}
catch
{
Response.Write("有错误!");
}
}
}
一:OledbDataReader读取数据<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.Oledb" %>
<script language="vb" runat="server">
Sub Page_Load()
Dim strConnection as String = "Provider=Microsoft.Jet.OLEDB.4.0;"
strConnection += "Data Source=C:\BegASPNET\ch12\Northwind.mdb"
Dim strSQL as string = "SELECT FirstName, LastName FROM Employees"
Dim strResultsHolder as string Dim objConnection as New OledbConnection(strConnection)
Dim objCommand as New OledbCommand(strSQL, objConnection)
Dim objDataReader as OledbDataReader try
objConnection.Open()
con_open.text="Connection opened successfully.<br />"
objDataReader = objCommand.ExecuteREader() Do While objDataReader.Read()=True
strResultsHolder +=objDataREader("FirstName")
strResultsHolder +=" "
strResultsHolder +=objDataREader("LastName")
strResultsHolder +="<br>"
Loop objDataReader.Close()
objConnection.Close()
con_close.text="Connection closed.<br>"
divListEmployees.innerHTML = strResultsHolder
catch e as Exception
con_open.text="Connection failed to open successfully.<br>"
con_close.text=e.ToString()
end try
end Sub
</script><html>
<body>
<h4>Reading data from the connection
<asp:label id="data_src" runat="server"/> with the DataReader object.</h4>
<asp:label id="con_open" runat="server"/><br>
<div id="divListEmployees" runat="server">list will go here</div>
<asp:label id="con_close" runat="server"/><br>
</body>
</html>二:datagrid读取绑定数据<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.Oledb" %><script language="vb" runat="server">
Sub Page_Load()
Dim strConnection as String = "Provider=Microsoft.Jet.OLEDB.4.0;"
strConnection += "Data Source=C:\begASPNET\ch12\Northwind.mdb"
data_src.text = strConnection
Dim strSQL as string = "SELECT FirstName, LastName FROM Employees;"
Dim objDataSet as new DataSet() Dim objConnection as new OledbConnection(strConnection)
Dim objAdapter as new OledbDataAdapter(strSQL, objConnection) objAdapter.Fill(objDataSet, "Employees") Dim objDataView as New DataView(objDataSet.Tables("Employees")) dgNameList.DataSource=objDataView
dgNameList.DataBind()
end Sub
</script>
<html>
<body>
<h4>Reading data from the connection
<asp:label id="data_src" runat="server"/> to the DataGrid control.</h4>
<asp:datagrid id="dgNameList" runat="server" /><br />
</body>
</html>