谁能给我一个vs2005连接sql server 2005数据库的例子
谁能给我一个在windows server 2003下visual studio 2005连接sql server 2005数据库的例子。先谢谢! 问题点数:10、回复次数:2Top
1 楼iuhxq(小灰)回复于 2006-03-18 11:32:01 得分 5
<%@ Page Language="C#" %>
<html>
<head runat="server">
<title>GridView Bound to SqlDataSource</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" DataSourceID="SqlDataSource1" runat="server" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
SelectCommand="SELECT [au_id], [au_lname], [au_fname], [phone], [address], [city], [state], [zip], [contract] FROM [authors]"
ConnectionString="<%$ ConnectionStrings:Pubs %>" />
</form>
</body>
</html>
web.config
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<!--
This connection is inherited from the ASP.NET Quickstart Web.config file
Uncomment this section to edit the sample locally
<add name="Pubs" connectionString="Server=(local)\SQLExpress;Integrated Security=True;Database=pubs;Persist Security Info=True"
providerName="System.Data.SqlClient" />
<add name="Northwind" connectionString="Server=(local)\SQLExpress;Integrated Security=True;Database=Northwind;Persist Security Info=True"
providerName="System.Data.SqlClient" />
<add name="Contacts" connectionString="Server=(local)\SQLExpress;Integrated Security=True;Database=Contacts;Persist Security Info=True"
providerName="System.Data.SqlClient" />
-->
<add name="NorthwindOLEDB" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|Northwind.mdb;"
providerName="System.Data.OleDb" />
<add name="ContactsDatabase" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True;User Instance=true;"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<pages styleSheetTheme="Default"/>
<caching>
<sqlCacheDependency enabled="true" pollTime="1000">
<databases>
<add name="Pubs" connectionStringName="Pubs"/>
</databases>
</sqlCacheDependency>
</caching>
</system.web>
</configuration>
Top
2 楼hblzg(心开风神)回复于 2006-03-18 11:38:48 得分 5
插入SqlDataSource控件,一步步提示的很简单。
如果自己写和2003的一样,webconfig中写连接字符串。。。Top




