Spread for ASP.NET 8.0 Product Documentation > Developer's Guide > Maintaining State > Saving Data to an SQL Database |
Database state management saves data to a specified database. Using an SQL database for state management is best if you are working with large amounts of data, particularly data that needs to be secure and maintain integrity.
To save data to an SQL database, you must install SQL State Management, as explained in the example.
The advantages of using a database to maintain state are:
The disadvantages of using a database to maintain state are:
This example describes how to install SQL state management, and provides code for setting up the FpSpread component. To install SQL State Management complete the following instructions.
OSQL –S localhost –U sa –P <InstallSqlState.sql
sqlConnectionString="data source=127.0.0.1;user id=sa;password=;"
Then you need to put the following code in your FpSpread component’s SaveOrLoadSheetState event:
The actual state information that you save is written to the tempdb database.
The following sample illustrates using the SQL state management to save data.
C# |
Copy Code
|
---|---|
protected void FpSpread1_SaveOrLoadSheetState(object sender, FarPoint.Web.Spread.SheetViewStateEventArgs e) { if (e.IsSave) { Session("data" + e.Index) == e.SheetView.SaveViewState(); } else { object o = Session("data" + e.Index); if ((o != null)) { e.SheetView.LoadViewState(o); } } e.Handled = true; } |
VB |
Copy Code
|
---|---|
Private Sub FpSpread1_SaveOrLoadSheetState(ByVal sender As Object, ByVal e As FarPoint.Web.Spread.SheetViewStateEventArgs) Handles FpSpread1.SaveOrLoadSheetState If (e.IsSave) Then Session("data"&e.Index) = e.SheetView.SaveViewState() Else Dim o As Object = Session("data"&e.Index) If Not o Is Nothing Then e.SheetView.LoadViewState(0) End If End If e.Handled = True End Sub |