Using System.Data; Using System.Data.OleDb;
<%@ Import Namespace="System.Data"%> <%@ Import Namespace="System.Data.OleDb"%> <%@ Page Language="C#" Debug="true" %> <script runat="server"> void Page_Load(object sender, EventArgs e) { Object myValue; myValue = exExecuteScalar(); lblText.Text = myValue.ToString(); } protected Object exExecuteScalar() { System.Data.OleDb.OleDbConnection objConn; System.Data.OleDb.OleDbCommand objCmd; String strConnString,strSQL; Object myScalar; strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("database/mydatabase.mdb")+";Jet OLEDB:Database Password=;"; objConn = new System.Data.OleDb.OleDbConnection(strConnString); objConn.Open(); strSQL = "SELECT MAX(Used) FROM customer"; objCmd = new System.Data.OleDb.OleDbCommand(); objCmd.Connection = objConn; objCmd.CommandType = CommandType.Text; objCmd.CommandText = strSQL; myScalar = objCmd.ExecuteScalar(); objCmd = null; objConn.Close(); objConn.Close(); objConn = null; return myScalar; } </script> <html> <head> <title>ThaiCreate.Com ASP.NET - System.Data.OleDb</title> </head> <body> <form id="form1" runat="server"> <asp:Label id="lblText" runat="Server"></asp:Label> </form> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท