新安数据

您的当前位置:网站首页 » 帮助中心» 数据库相关

在ASP.NET中,如何数据库的连接调用?

来源:新安数据类型:帮助文件 更新:2013-7-25 点击:23775

以下是我们用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>

我们很乐意帮助您!请联系在线客服或致电我们。7×24小时客服热线: 0551-62886237