连接数据库
<script language="C#" runat="server">
private void Page_Load(object sender,System.EventArgs e)
{
String strConnection = "server = (local)\\FUBINLIN;database=Northwind;integrated security=true;";
SqlConnection objConnection = new SqlConnection(strConnection);
String strSQL = "SELECT FirstName,LastName,Country " + "FROM Employees";
SqlCommand objCommand = new SqlCommand(strSQL,objConnection);
objConnection.Open();
dgNameList.DataSource = objCommand.ExecuteReader();
dgNameList.DataBind();
objConnection.Close();
}
</script>
<%@ Import namespace="System.Data.SqlClient"%>
<%@ Import namespace="System.Data"%>
<%@ Page language="c#" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Beginning ASP.NET Databases Using C#</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<h4>First Example:Listing data from the Employee table</h4>
<asp:DataGrid ID="dgNameList" Runat="server" GridLines="None" BackColor="LightBlue" CellPadding="5"
CellSpacing="5" BorderWidth="2" BorderColor="Black" ToolTip="Include only those employees who are at HQ" />
</body>
</HTML>
数据库我也打开了,运行时提示错误为:数据库不存在或数据库拒绝访问