无法使用GridView(ASP.net)访问MS Access数据库

时间:2018-07-16 03:40:04

标签: c# html asp.net database ms-access-2010

我是ASP.net的初学者。我正在使用Microsoft Access数据库。我没有收到任何错误,但是仍然无法显示数据库中的数据。

我的.aspx文件是:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="delivered.aspx.cs" Inherits="delivered" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <title>Delivered Works</title>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
   <link rel="stylesheet" type="text/css" href="css/StyleSheet.css" />
</head>
<body>
   <form id="form1" runat="server">
   <div>
   <div class="container-fluid">
    <a href="index.aspx"style="text-decoration:none;color:black;"><h1 style="font-family:Brush Script Std;font-size:54pt;">Boutique Manager</h1></a>
   <asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
    </asp:GridView>
  </form>
</body>
</html>

我的.aspx.cs文件是:

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;

public partial class delivered : System.Web.UI.Page
  {
      OleDbCommand cmd = new OleDbCommand();
      OleDbConnection con = new OleDbConnection();
      protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
       {
         System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
         conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\000silpa\boutique\database\Boutique.accdb";

          try
              {

               OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\000silpa\boutique\database\Boutique.accdb");
               con.Open();
               OleDbCommand cmd = new OleDbCommand("select PhNo,Names,Cloth from customer where status="delivered", con");
               OleDbDataReader dr = cmd.ExecuteReader();
               GridView1.DataSource = dr;
               GridView1.DataBind();
              }
         catch (Exception ex)
              {

              }
         }
      }

我的数据库屏幕截图是: enter image description here

0 个答案:

没有答案