CSDN博客

img bgu

[我的ASP.net学习历程]Try错误信息处理

发表于2004/9/21 20:13:00  775人阅读

分类: [My ASP/ASP.net(C#)]

<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
<script language="C#" runat="server">

 void Page_Load()
 {
  string DB_path = @"Data/db.mdb"; //把路径更改可看到错误信息
  string DB = Server.MapPath(DB_path);
  string strSQL = "SELECT * FROM admin";
  string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DB;
  
  System.Data.OleDb.OleDbDataReader dr;
  System.Data.OleDb.OleDbConnection conn = null;
  System.Data.OleDb.OleDbCommand cmd = null;
  
//=======================================================
  try
  {
   conn = new System.Data.OleDb.OleDbConnection(connString);
   cmd = new System.Data.OleDb.OleDbCommand(strSQL,conn);
   cmd.Connection.Open();
  }
  catch (Exception ex)
  {
   conn.Close();
   Response.Write("Connection was closed!<br>" + ex.Message);
   return;
  }
//=======================================================
  
  dr = cmd.ExecuteReader();
  DataGrid1.DataSource = dr;
  DataGrid1.DataBind();
  conn.Close();

 }
 
</script>

<asp:datagrid ID="DataGrid1" runat="server"></asp:datagrid>

0 0

相关博文

我的热门文章

img
取 消
img