<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat=server>
void Page_Load(Object sender , EventArgs e)
{
DataSet dstProducts;
SqlConnection conNorthwind;
SqlDataAdapter dadProducts;
// Grab Products Table
dstProducts = new DataSet();
conNorthwind = new SqlConnection("server=IPROMISE;database=Northwind;uid=sa;password=;");
dadProducts = new SqlDataAdapter( "Select * from Products", conNorthwind );
dadProducts.Fill( dstProducts, "Products");
// Add Unique Constraint
DataTable dtblProducts = dstProducts.Tables[ "Products" ];
UniqueConstraint objConstraint = new UniqueConstraint(dtblProducts.Columns[ "ProductName" ]);
dstProducts.Tables[ "Products" ].Constraints.Add( objConstraint );
// Bind to DataGrid
dgrdProducts.DataSource = dstProducts;
dgrdProducts.DataBind();
}
</Script>
<html>
<head><title>UniqueConstraint.aspx</title></head>
<body>
<asp:DataGrid
ID="dgrdProducts"
Runat="Server" />
</body>
</html>