Hi Everybody
This Code duplicate the record in the database, can somebody help me understand why that happen.
Thanks a LOT
CompanyName:
<asp:textbox id="txtCompanyName" runat="server" /><br />
Phone:
<asp:textbox id="txtPhone" runat="server" /><br />
<br />
<asp:button id="btnSubmit" runat="server" text="Submit" onclick="btnSubmit_Click" />
<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:dsn %>"
insertcommand="INSERT INTO [items] ([smId], [iTitleSP]) VALUES (@.CompanyName, @.Phone)"
selectcommand="SELECT * FROM [items]">
<insertparameters>
<asp:controlparameter controlid="txtCompanyName" name="CompanyName" />
<asp:controlparameter controlid="txtPhone" name="Phone" />
</insertparameters>
</asp:sqldatasource>
VB
Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
SqlDataSource1.Insert()
End Sub
End Class
--------------
Yes is an Identity the Primary Key of the Table items
Please include the btnSubmit_Click ~ Code ~
Also, verify that the primary key in items is an identity
DK
|||You have the click event hooked up twice (remove one of the red sections):
CompanyName:
<asp:textbox id="txtCompanyName" runat="server" /><br />
Phone:
<asp:textbox id="txtPhone" runat="server" /><br />
<br />
<asp:button id="btnSubmit" runat="server" text="Submit"onclick="btnSubmit_Click" />
<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:dsn %>"
insertcommand="INSERT INTO [items] ([smId], [iTitleSP]) VALUES (@.CompanyName, @.Phone)"
selectcommand="SELECT * FROM [items]">
<insertparameters>
<asp:controlparameter controlid="txtCompanyName" name="CompanyName" />
<asp:controlparameter controlid="txtPhone" name="Phone" />
</insertparameters>
</asp:sqldatasource>
VB
Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)Handles btnSubmit.Click
SqlDataSource1.Insert()
End Sub
End Class
No comments:
Post a Comment