原創(chuàng)|其它|編輯:郝浩|2012-09-11 15:20:37.000|閱讀 436 次
概述:Aspose.Cells要將數(shù)據(jù)庫綁定到一個(gè)工作表,應(yīng)遵循的步驟為:訪問將被綁定的表……
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Aspose.Cells要將數(shù)據(jù)庫綁定到一個(gè)工作表,應(yīng)遵循以下步驟:
實(shí)例代碼:
[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
最后,編譯并運(yùn)行此Web應(yīng)用程序的。 Web窗體加載后,你會(huì)看到從數(shù)據(jù)庫加載到工作表中的數(shù)據(jù):
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)