Spread ASP.NET 17
FarPoint.Web.Spread Assembly / FarPoint.Web.Spread.Model Namespace / DefaultSheetDataModel Class / DataKeyField Property
Example


In This Topic
    DataKeyField Property (DefaultSheetDataModel)
    In This Topic
    Gets or sets a row identifier.
    Syntax
    'Declaration
     
    
    Public Property DataKeyField As Object
    'Usage
     
    
    Dim instance As DefaultSheetDataModel
    Dim value As Object
     
    instance.DataKeyField = value
     
    value = instance.DataKeyField
    public object DataKeyField {get; set;}

    Property Value

    Object containing the data key
    Remarks
    Use the key to associate data with the active row.
    Example
    This example creates a new DefaultSheetDataModel, binds it to a database and attaches it to the DataModel of the active sheet. It does not automatically generate its columns based on the columns in the database, but does so on an individual basis.
    PrivateSubPage_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles MyBase.Load
    
    If(IsPostBack)ThenReturn
    Dim conStr As String ="Provider=Microsoft.JET.OLEDB.4.0;datasource=d:\\nwind.mdb"
    Dim sqlStr As String ="SELECT*FROMEmployees"
    Dim conn As System.Data.OleDb.OleDbConnection=New System.Data.OleDb.OleDbConnection(conStr)
    Dim ds As DataSet=New DataSet()
    Dim da As System.Data.OleDb.OleDbDataAdapter=New System.Data.OleDb.OleDbDataAdapter(sqlStr,conn)
    da.Fill(ds,"Employees")
    Dim dm As New FarPoint.Web.Spread.Model.DefaultSheetDataModel()
    dm.DataSource=ds
    dm.AutoGenerateColumns=False
    dm.SetModelDataColumn(0,2)
    dm.SetModelDataColumn(1,1)
    dm.DataKeyField="LastName"
    FpSpread1.ActiveSheetView.DataModel=dm
    conn.Close()
    ListBox1.Items.Add(dm.ColumnCount)
    ListBox1.Items.Add(dm.RowCount)
    EndSub
    private void Page_Load(object sender, System.EventArgs e)
    {
    string conStr="Provider=Microsoft.JET.OLEDB.4.0;datasource=d:\\nwind.mdb";
    string sqlStr="SELECT*FROMEmployees";
    System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(conStr);
    DataSet ds = new DataSet();
    System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter(sqlStr,conn);
    da.Fill(ds,"Employees");
    FarPoint.Web.Spread.Model.DefaultSheetDataModel dm = new FarPoint.Web.Spread.Model.DefaultSheetDataModel(ds,"Employees");
    dm.DataSource=ds;
    dm.AutoGenerateColumns=false;
    dm.SetModelDataColumn(0,2);
    dm.SetModelDataColumn(1,1);
    dm.DataKeyField="LastName";
    FpSpread1.ActiveSheetView.DataModel=dm;
    conn.Close();
    ListBox1.Items.Add(Convert.ToString(dm.ColumnCount));
    ListBox1.Items.Add(Convert.ToString(dm.RowCount));
    }
    See Also