MSSQL数据库使用ASP.NET连接调用样例

Tags: 主机  空间  MSSQL  Author:凯旋网络   Date:2012/7/24

以下是我们用C#来实现的,见下列实例代码,请凯旋网络独立服务器客户参考:< %@ Import Namespace="System.Data" %><%@ Import Namespace="System.Data.SQL" %>  <html>< script language="C#" runat="server">'' 声明C# public DataSet dsCustomer;protected void Page_Load(Object Src, EventArgs E ) { '' 在打开页面时连接数据库 SQLConnection myConnection = new SQLConnection("server=127.0.0.1;uid=xxx;pwd=*****;database=***_db"); SQLDataSetCommand CustomersDSCommand = new SQLDataSetCommand("select * from customers", myConnection); dsCustomer = new DataSet(); CustomersDSCommand.FillDataSet(dsCustomer,"Customers");foreach (DataRow Customer in dsCustomer.Tables["Customers"].Rows){Response.Write(Customer["CustomerId"].ToString() + "<br> " ); } } </script><body></body></html> </td></tr></table></body> 注:如果您使用的是G享服务器,数据库和WEB是分离机制,请您在页面程序代码调用数据库时,不要使用local或者127.0.0.1等本机调用,使用凯旋网络提供的数据库地址,MSSQL地址dsc-序号.35yi.com,具体序号,需要您登录凯旋网络会员区后,进入主机管理->点击相应的主机登陆名->查看主机的相关信息。