彩票走势图

如何在Spread ASP.NET中显示数据库的数据关系?

原创|其它|编辑:郝浩|2012-11-13 10:37:13.000|阅读 397 次

概述:在Spread ASP.NET中显示数据库的中数据关系,附加源码。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

今天来看看如何在Spread ASP.NET中显示数据库的数据关系,如下所示:

为了设置层级数据显示,首先需要创建一个数据集,用来表示数据关系,然后就是定义数据数据之间的关系,最后设置控件显示出你想要的数据效果,在下面的例子中就会详细的讲到:

在这个例子中,将这个控件绑定到了一个数据集上面,这个数据集中包含了来自数据库的多个表格,然后设置控件层级的显示数据。

所用的代码如下:

Imports System.Data.OleDb
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
      If IsPostBack Then Return 
      ' Call subroutines to set up data and format the Spread component 
      InitData()
      FormatSpread()
End Sub
  
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
      ' Call subroutines to set up data and format the Spread component 
      InitData()
      FormatSpread()
End Sub
  
Private Sub InitData()
        Dim con As New OleDbConnection() 
        Dim cmd As New OleDbCommand() 
        Dim da As New OleDbDataAdapter() 
        Dim ds As New DataSet() 
        Dim dt As DataTable 
  
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\Program Files\GrapeCity\Spread.WebForms\Samples\Files\databind.mdb" 
con.Open()
  
With cmd
.Connection = con
.CommandType = CommandType.TableDirect
.CommandText = "Categories"
End With
  
da.SelectCommand = cmd
da.Fill(ds, "Categories")
  
cmd.CommandText = "Products"
da.SelectCommand = cmd
da.Fill(ds, "Products")
  
cmd.CommandText = "Inventory Transactions"
da.SelectCommand = cmd
da.Fill(ds, "Inventory Transactions")
  
ds.Relations.Add("Root", ds.Tables("Categories").Columns("CategoryID"), ds.Tables("Products").Columns("CategoryID"))

ds.Relations.Add("Secondary", ds.Tables("Products").Columns("ProductID"), ds.Tables("Inventory Transactions").Columns("TransactionID")) 
  
FpSpread1.DataSource = ds
End Sub
  
Private Sub FormatSpread()
With FpSpread1.Sheets(0)
.ColumnHeader.Rows(0).Height = 30
.Columns(0).Visible = False
            .Columns(0).Width = 200 
End With
End Sub
  
Private Sub FpSpread1_ChildViewCreated(ByVal sender As Object, ByVal e As FarPoint.Web.Spread.ChildViewCreatedEventArgs) Handles FpSpread1.ChildViewCreated 
Dim dateType As New FarPoint.Web.Spread.DateTimeCellType()
  
If e.SheetView.RelationName = "Root" Then
With e.SheetView
.DataAutoCellTypes = False
.ColumnHeader.Rows(0).Height = 30
.Columns(0).Visible = False
.Columns(3).Visible = False
.Columns(4).Visible = False
.Columns(1).Width = 200
.Columns(2).Width = 185
.Columns(6).Width = 85
.Columns(7).Width = 80
.Columns(8).Width = 80
.Columns(5).CellType = New FarPoint.Web.Spread.CurrencyCellType()
.Columns(7.CellType) = New FarPoint.Web.Spread.CheckBoxCellType()
End With
Else
With e.SheetView
.DataAutoCellTypes = False
.DataAutoSizeColumns = False
.ColumnHeader.Rows(0).Height = 30
.Columns(0).Visible = False
.Columns(2).Visible = False
.Columns(3).Visible = False
.Columns(4).Visible = False
.Columns(7).Visible = False
.Columns(8).Visible = False
.Columns(9).Visible = False
.Columns(1).Width = 100
.Columns(6).Width = 80
.Columns(5).CellType = New FarPoint.Web.Spread.CurrencyCellType()
.Columns(1).CellType = dateType
'Add a total column
.ColumnCount = .ColumnCount + 1
.ColumnHeader.Cells(0, .ColumnCount - 1).Value = "Total" 
.Columns(.ColumnCount - 1).CellType = New FarPoint.Web.Spread.CellType.CurrencyCellType()
.Columns(.ColumnCount - 1).Formula = "F1*G1"
End With
End If

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:慧都控件

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP