⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datareader-oledb.aspx

📁 东软内部材料(四)asp等相关的教学案例 
💻 ASPX
字号:
<%@Page Language="C#"%>

<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.OleDb" %>

<%@ Register TagPrefix="wrox" TagName="connect" Src="..\global\connect-strings.ascx" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>The .NET OleDbDataReader and OleDbConnection Objects</title>
<!-- #include file="..\global\style.inc" -->
</head>
<body bgcolor="#ffffff">
<span class="heading">The .NET OleDbDataReader and OleDbConnection Objects</span><hr />
<!--------------------------------------------------------------------------->

<%-- insert connection string script --%>
<wrox:connect id="ctlConnectStrings" runat="server"/>

<div>Connection string: <b><span id="outConnect" runat="server"></span></b></div>
<div>SELECT command: <b><span id="outSelect" runat="server"></span></b></div>
<div id="outError" runat="server">&nbsp;</div>
<div id="outResult" runat="server"></div>

<script language="C#" runat="server">

	void Page_Load(Object sender, EventArgs e)
	{
		// declare a string to hold the results as an HTML table
		string strResult = "<table>";

		// get connection string from ..\global\connect-strings.ascx user control
		string strConnect = ctlConnectStrings.OLEDBConnectionString;
		outConnect.InnerText = strConnect;		// and display it

		// specify the SELECT statement to extract the data
		string strSelect = "SELECT * FROM BookList WHERE ISBN LIKE '1861003%'";
		outSelect.InnerText = strSelect;		// and display it

		try
		{
			// create a new Connection object using the connection string
			OleDbConnection objConnect = new OleDbConnection(strConnect);

			// open the connection to the database
			objConnect.Open();

			// create a new Command using the connection object and select statement
			OleDbCommand objCommand = new OleDbCommand(strSelect, objConnect);

			// declare a variable to hold a DataReader object
			OleDbDataReader objDataReader;

			// execute the SQL statement against the command to fill the DataReader
			objDataReader = objCommand.ExecuteReader();

			// iterate through the records in the DataReader getting field values
			// the Read method returns False when there are no more records
			while (objDataReader.Read())
			{
				strResult += "<tr><td>" + objDataReader["ISBN"] + "</td><td> &nbsp;"
							+ objDataReader["Title"] + "</td><td> &nbsp;"
							+ objDataReader["PublicationDate"] + "</td></tr>";
			}

			// close the DataReader and Connection
			objDataReader.Close();
			objConnect.Close();
		}
		catch (Exception objError)
		{
			// display error details
			outError.InnerHtml = "<b>* Error while accessing data</b>.<br />"
							+ objError.Message + "<br />" + objError.Source;
			return;		//  and stop execution
		}

		// add closing table tag and display the results
		strResult += "</table>";
		outResult.InnerHtml = strResult;

	}
	
</script>


<!--------------------------------------------------------------------------->
<!-- #include file="..\global\foot.inc" -->
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -