LinqDataSource.InsertParameters Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the collection of parameters that are used during an insert operation.
public:
property System::Web::UI::WebControls::ParameterCollection ^ InsertParameters { System::Web::UI::WebControls::ParameterCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public System.Web.UI.WebControls.ParameterCollection InsertParameters { get; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.InsertParameters : System.Web.UI.WebControls.ParameterCollection
Public ReadOnly Property InsertParameters As ParameterCollection
Property Value
The parameters that are used during an insert operation.
- Attributes
Examples
The following example shows a LinqDataSource control with a parameter that provides a default value in the InsertParameters collection. If the user does not provide a value for the Category
property, the default value that is provided by the parameter is saved in the database.
<asp:LinqDataSource
ContextTypeName="ExampleDataContext"
TableName="Products"
EnableUpdate="true"
EnableInsert="true"
ID="LinqDataSource1"
runat="server">
<UpdateParameters>
<asp:Parameter Name="Category" DefaultValue="Miscellaneous" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Category" DefaultValue="Miscellaneous" />
</InsertParameters>
</asp:LinqDataSource>
<asp:GridView
DataSourceID="LinqDataSource1"
ID="GridView1"
runat="server">
</asp:GridView>
<asp:LinqDataSource
ContextTypeName="ExampleDataContext"
TableName="Products"
EnableUpdate="true"
EnableInsert="true"
ID="LinqDataSource1"
runat="server">
<UpdateParameters>
<asp:Parameter Name="Category" DefaultValue="Miscellaneous" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Category" DefaultValue="Miscellaneous" />
</InsertParameters>
</asp:LinqDataSource>
<asp:GridView
DataSourceID="LinqDataSource1"
ID="GridView1"
runat="server">
</asp:GridView>
Remarks
Typically the values that are needed for an insert operation are passed to the LinqDataSource control by the data-bound control. You specify insert parameters when you want to provide a default value or define whether to convert empty values to null
. You do not have to provide a parameter for every value that will be inserted, only for the values that must be handled when the user does not provide a value.
The values that you provide in the InsertParameters collection are used only for fields that are defined in the data source but that are not bound in the data control. For example, suppose a database table has columns that are named Name, Address, and PostalCode, but a ListView control that is bound to the table is bound only to the Name and Address fields. The values in the InsertParameters collection will be used only for the PostalCode field. They will not be used for the Name and Address field. This is true even if no value is entered for those fields. If the data-bound control autogenerates fields for all fields in the data source, no values from the InsertParameters collection will be used.