原創|其它|編輯:郝浩|2012-09-11 15:20:37.000|閱讀 443 次
概述:Aspose.Cells要將數據庫綁定到一個工作表,應遵循的步驟為:訪問將被綁定的表……
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Aspose.Cells要將數據庫綁定到一個工作表,應遵循以下步驟:
實例代碼:
[C#]
//Implementing Page_Load event handler
private void Page_Load(object sender, System.EventArgs e)
{
//Checking if there is not any PostBack
if (!IsPostBack)
{
//Accessing a desired worksheet
WebWorksheet sheet = GridWeb1.WebWorksheets[0];
//Specifying Data Source for the worksheet
sheet.DataSource = dataSet11;
//Specifying Products tables as the DataMember
sheet.DataMember = "Products";
//Creating data bound columns automatically
sheet.CreateAutoGenratedColumns();
//Creating REQUIRED validation for ProductID column
Validation v = new Validation();
v.IsRequired = true;
sheet.BindColumns[0].Validation = v;
//Setting Number Format of ProductPrice column to Currency3
sheet.BindColumns[2].NumberType = NumberType.Currency3;
try
{
//Filling DataSet
oleDbDataAdapter1.Fill(dataSet11);
}
finally
{
//Closing database connection
oleDbConnection1.Close();
}
//Binding worksheet with DataSet
sheet.DataBind();
}
}
[VB.NET]
'Implementing Page_Load event handler
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Checking if there is not any PostBack
If Not IsPostBack Then
'Accessing a desired worksheet
Dim sheet As WebWorksheet = GridWeb1.WebWorksheets(0)
'Specifying Data Source for the worksheet
sheet.DataSource = dataSet11
'Specifying Products tables as the DataMember
sheet.DataMember = "Products"
'Creating data bound columns automatically
sheet.CreateAutoGenratedColumns()
'Creating REQUIRED validation for ProductID column
Dim v As Validation = New Validation()
v.IsRequired = True
sheet.BindColumns(0).Validation = v
'Setting Number Format of ProductPrice column to Currency3
sheet.BindColumns(2).NumberType = NumberType.Currency3
Try
'Filling DataSet
oleDbDataAdapter1.Fill(dataSet11)
Finally
'Closing database connection
oleDbConnection1.Close()
End Try
'Binding worksheet with DataSet
sheet.DataBind()
End If
End Sub
最后,編譯并運行此Web應用程序的。 Web窗體加載后,你會看到從數據庫加載到工作表中的數據:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn
文章轉載自:慧都控件網