验证中...
Languages: ASP
Categories: Web开发技术
Latest update 2018-12-25 08:50
使用OLeDbCommand类
Raw Copy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
namespace Listbox
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String sqlUrl = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\asp.net\数据库文件\Northwind新建文件夹\Northwind.mdb;Jet OLEDB:Database Password=111111";
OleDbConnection conn = new OleDbConnection(sqlUrl);
conn.Open();
OleDbCommand comm = new OleDbCommand("SELECT * FROM 运货商", conn);
//OleDbCommand comm = conn.CreateCommand();
//comm.CommandText = "SELECT * FROM 运货商";
OleDbDataReader dr;
dr = comm.ExecuteReader();
Response.Write("<h3>使用OleDbCommand类读取数据</h3><hr/>");
Response.Write("<table border=1 cellspacing=0 cellpaddig=2>");
Response.Write("<tr>");
for (int i = 0; i < dr.FieldCount; i++)
{
Response.Write("<td>" + dr.GetName(i) + "</td>");
}
Response.Write("</tr>");
while (dr.Read())
{
Response.Write("<tr>");
for (int i = 0; i < dr.FieldCount; i++)
{
Response.Write("<td>"+dr[i].ToString()+"</td>");
}
Response.Write("</tr>");
}
Response.Write("</table>");
dr.Close();
conn.Close();
}
}
}

Comment list( 0 )

You need to Sign in for post a comment

Help Search

Gitee_sixth 5th_float_left_close