LinqDataSource.Insert(IDictionary) Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Voert een invoegbewerking uit.
public:
int Insert(System::Collections::IDictionary ^ values);
public int Insert(System.Collections.IDictionary values);
member this.Insert : System.Collections.IDictionary -> int
Public Function Insert (values As IDictionary) As Integer
Parameters
- values
- IDictionary
De rijwaarden die moeten worden ingevoegd in de gegevensbron.
Retouren
Het aantal rijen dat wordt beïnvloed door de invoegbewerking.
Voorbeelden
In het volgende voorbeeld ziet u hoe u programmatisch een nieuwe record in de gegevensbron invoegt nadat de gebruiker op een knop heeft geklikt. De code geeft een ListDictionary object met standaardwaarden door aan de Insert methode.
protected void Add_Click(object sender, EventArgs e)
{
System.Collections.Specialized.ListDictionary listDictionary
= new System.Collections.Specialized.ListDictionary();
listDictionary.Add("ProductName", TextBox1.Text);
listDictionary.Add("ProductCategory", "General");
listDictionary.Add("Color", "Not assigned");
listDictionary.Add("ListPrice", null);
LinqDataSource1.Insert(listDictionary);
TextBox1.Text = String.Empty;
DetailsView1.DataBind();
}
Protected Sub Add_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim listDictionary As New System.Collections.Specialized.ListDictionary()
listDictionary.Add("ProductName", TextBox1.Text)
listDictionary.Add("ProductCategory", "General")
listDictionary.Add("Color", "Not assigned")
listDictionary.Add("ListPrice", Nothing)
LinqDataSource1.Insert(listDictionary)
TextBox1.Text = String.Empty
DetailsView1.DataBind()
End Sub
In het volgende voorbeeld ziet u de markeringen voor het vorige voorbeeld.
<asp:LinqDataSource
ContextTypeName="ExampleDataContext"
TableName="Products"
EnableInsert="true"
ID="LinqDataSource1"
runat="server">
</asp:LinqDataSource>
<asp:DetailsView
DataSourceID="LinqDataSource1"
AllowPaging="true"
ID="DetailsView1"
runat="server">
</asp:DetailsView>
New product name:<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:button ID="Button1"
Text="Add new product with default values"
runat="server"
onclick="Add_Click" />
<asp:LinqDataSource
ContextTypeName="ExampleDataContext"
TableName="Products"
EnableInsert="true"
ID="LinqDataSource1"
runat="server">
</asp:LinqDataSource>
<asp:DetailsView
DataSourceID="LinqDataSource1"
AllowPaging="true"
ID="DetailsView1"
runat="server">
</asp:DetailsView>
New product name:<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:button ID="Button1"
Text="Add new product with default values"
runat="server"
onclick="Add_Click" />
Opmerkingen
Normaal gesproken hoeft u de Insert methode niet aan te roepen vanuit uw code. Het gegevensgebonden besturingselement roept automatisch de Insert methode aan wanneer de gebruiker actie onderneemt om een nieuwe record in te voegen. U roept de Insert methode expliciet aan wanneer u uw eigen proces wilt maken voor het invoegen van gegevens.