grid中一个必须指定的属性是fromPart,它表示表或者视图的名字。
with
(document.all.dbnetgrid1)
... {
...
fromPart="customers"
...
}
... {
...
fromPart="customers"
...
}
你也可以指定多个表或者视图,但是必须说明它们的连接信息。
注意:如果用的是存储过程就不需要用fromPart指定了
从多个表中提取数据
可以利用joinPart属性来从多个表中选择数据,如下:
with (document.all.dbnetgrid1)
{
...
headings = ["Product","Unit Price","Quantity","Discount (%)"]
selectPart = ["products.productname","[order details].unitprice","[order details].quantity","([order details].discount * 100)"]
fromPart = "[order details], products"
joinPart = "[order details].productid = products.productid"
...
}
{
...
headings = ["Product","Unit Price","Quantity","Discount (%)"]
selectPart = ["products.productname","[order details].unitprice","[order details].quantity","([order details].discount * 100)"]
fromPart = "[order details], products"
joinPart = "[order details].productid = products.productid"
...
}
如果你用的是sql server,你可以在fromPart中包含
join
的指令
with (document.all.dbnetgrid1)
{
...
headings = ["Product","Unit Price","Quantity","Discount (%)"]
selectPart = ["products.productname","[order details].unitprice","[order details].quantity","([order details].discount * 100)"]
fromPart = "[order details] join products on [order details].productid = products.productid"
...
}
{
...
headings = ["Product","Unit Price","Quantity","Discount (%)"]
selectPart = ["products.productname","[order details].unitprice","[order details].quantity","([order details].discount * 100)"]
fromPart = "[order details] join products on [order details].productid = products.productid"
...
}
注意:从多个表中取数据,选择列时需要以
表名
.
列名的格式来引用