⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 column-constraints.aspx

📁 This is a book about vb.you could learn this from this book
💻 ASPX
字号:
<%@Page Language="VB"%>

<%@Import Namespace="System.Data" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>Adding Expressions, Default Values and Constraints to a Table</title>
<!-- #include file="..\global\style.inc" -->
</head>
<body bgcolor="#ffffff">
<span class="heading">Adding Expressions, Default Values and Constraints to a Table</span><hr />
<!--------------------------------------------------------------------------->

<asp:datagrid id="dgrResult" runat="server" />

<script language="vb" runat="server">

Sub Page_Load()

   'create a new empty DataTable object
   Dim objTable As New DataTable("NewBooks")

   'declare a variable to hold a DataColumn object
   Dim objColumn As DataColumn

   'define the columns (fields) within the table
   'the first is an AutoIncrement column to act as the key
   objColumn = objTable.Columns.Add("kBookKey", System.Type.GetType("System.Int32"))
   objColumn.AutoIncrement = True
   objColumn.AutoIncrementSeed = 1000
   objColumn.AutoIncrementStep = 10

   'next, the ISBN column which must be unique and not allow Null values
   objColumn = objTable.Columns.Add("ISBN", System.Type.GetType("System.String"))
   objColumn.AllowDBNull = False
   objColumn.Unique = True
   objColumn.MaxLength = 10

   'now two more columns to hold general information
   objTable.Columns.Add("Title", System.Type.GetType("System.String"))
   objTable.Columns.Add("PublicationDate", System.Type.GetType("System.DateTime"))

   'add two columns to hold stock and order quantities, with default values of zero
   objColumn = objTable.Columns.Add("StockQty", System.Type.GetType("System.Int32"))
   objColumn.DefaultValue = 0
   objColumn = objTable.Columns.Add("OrderedQty", System.Type.GetType("System.Int32"))
   objColumn.DefaultValue = 0

   'add a column containing an expression showing the quantity availability
   objColumn = objTable.Columns.Add("AvailableQty", System.Type.GetType("System.Int32"))
   objColumn.Expression = "[StockQty] - [OrderedQty]"

   'declare a variable to hold a DataRow object
   Dim objDataRow As DataRow

   'create a new DataRow object instance in this table
   objDataRow = objTable.NewRow()

   'and fill in the values
   objDataRow("ISBN") = "1234567800"
   objDataRow("Title") = "Professional Video Recorder Programming"
   objDataRow("PublicationDate") = "2001-03-01"
   objDataRow("StockQty") = 3956
   objDataRow("OrderedQty") = 450
   objTable.Rows.Add(objDataRow)

   'repeat to add two more rows
   objDataRow = objTable.NewRow()
   objDataRow("ISBN") = "1234567801"
   objDataRow("Title") = "Professional WAP Phone Programming"
   objDataRow("PublicationDate") = "2001-06-01"
   objDataRow("StockQty") = 329
   'note - no "OrderedQty" provided so default value used
   objTable.Rows.Add(objDataRow)

   objDataRow = objTable.NewRow()
   objDataRow("ISBN") = "1234567802"
   objDataRow("Title") = "Professional Radio Station Programming"
   objDataRow("PublicationDate") = "2001-04-01"
   'note - no "StockQty" provided so default value used
   objDataRow("OrderedQty") = 1200
   objTable.Rows.Add(objDataRow)

   'assign the DataTable's DefaultView object to the DataGrid control
   dgrResult.DataSource = objTable.DefaultView
   dgrResult.DataBind()  'and bind (display) the data

End Sub
</script>


<!--------------------------------------------------------------------------->
<!-- #include file="..\global\foot.inc" -->
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -