Using System.Data; Using System.Data.Odbc;
<%@ Import Namespace="System.Data"%> <%@ Import Namespace="System.Data.Odbc"%> <%@ 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.Odbc.OdbcConnection objConn; System.Data.Odbc.OdbcCommand objCmd; String strConnString,strSQL; Object myScalar; strConnString = "DSN=mydatabase;UID=;PWD=;"; objConn = new System.Data.Odbc.OdbcConnection(strConnString); objConn.Open(); strSQL = "SELECT MAX(Used) FROM customer"; objCmd = new System.Data.Odbc.OdbcCommand(); 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.Odbc</title> </head> <body> <form id="form1" runat="server"> <asp:Label id="lblText" runat="Server"></asp:Label> </form> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท