Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
lars_toreh
Starting Member
29 Posts |
Posted - 2010-01-07 : 12:32:00
|
| My code look like this: <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" AutoGenerateRows="False" DataKeyNames="SalgID" DataSourceID="SqlDataSource2"> <Fields> <asp:BoundField DataField="SalgID" HeaderText="SalgID" InsertVisible="false" ReadOnly="true" /> <asp:BoundField DataField="Dato" HeaderText="Dato" /> <asp:BoundField DataField="Antall" HeaderText="Antall" /> <asp:BoundField DataField="Omsetning" HeaderText="Omsetning" /> <asp:CommandField ButtonType="Button" DeleteText="Slett" NewText="Lagre" ShowDeleteButton="True" ShowInsertButton="True" /> </Fields> </asp:DetailsView> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:BCDConnectionString13 %>" SelectCommand="SELECT [Dato], [Antall], [Omsetning], [SalgID] FROM [Salg]" InsertCommand="INSERT INTO [Salg] ([Dato], [Antall], [Omsetning]) VALUES (@Dato, @Antall, @Omsetning)" DeleteCommand="DELETE FROM [Salg] WHERE [SalgID] = @SalgID" UpdateCommand="UPDATE [Salg] SET [Dato] = @Dato, [Antall] = @Antall, [Omsetning] = @Omsetning WHERE [SalgID] = @SalgID"> <DeleteParameters> <asp:Parameter Name="SalgID" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="Dato" Type="DateTime" /> <asp:Parameter Name="Antall" Type="String" /> <asp:Parameter Name="Omsetning" Type="String" /> <asp:Parameter Name="SalgID" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="Dato" Type="DateTime" /> <asp:Parameter Name="Antall" Type="String" /> <asp:Parameter Name="Omsetning" Type="String" /> </InsertParameters> </asp:SqlDataSource>When I put in data into the textboxes and click the Insertbutton,it sends the same data twice to the database.How to avoid this?Thanks in advanced :)PS: I think it has something to do with,when I click the savebutton,it comes up a insertbutton too,I click both buttons. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-07 : 12:40:02
|
| what does below do? can you explain?<asp:CommandField ButtonType="Button" DeleteText="Slett" NewText="Lagre" ShowDeleteButton="True" ShowInsertButton="True" /> |
 |
|
|
lars_toreh
Starting Member
29 Posts |
Posted - 2010-01-07 : 14:25:49
|
| This is inside a Detailviews.In the properties for the Detailviews you can autogenerate buttons forexample update,insert,delete etc.You can change the style of the button,linkbutton is default.I choose buttonstyle.- ButtonType="Button"I have changed the text for the delete-button to norwegian.- DeleteText="Slett"I have changed the text for the insert-button to norwegian.- NewText="Lagre"CommandField is where you can put in buttons and such that will work inside the Detailviews and towards the database if you connect a datasource to it.Sorry,I took the basics,so someone with less experience can learn from it :) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-07 : 14:29:26
|
| sorry I'm a noobie in this, so are you using same button for delete,insert,update? |
 |
|
|
lars_toreh
Starting Member
29 Posts |
Posted - 2010-01-07 : 14:39:36
|
| No,there are two buttons,one Save(Lagre)/Insert button and one Delete button.- ShowDeleteButton="True" ShowInsertButton="True" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-08 : 02:16:33
|
quote: Originally posted by lars_toreh No,there are two buttons,one Save(Lagre)/Insert button and one Delete button.- ShowDeleteButton="True" ShowInsertButton="True"
where do you define action for each? |
 |
|
|
lars_toreh
Starting Member
29 Posts |
Posted - 2010-01-08 : 16:47:54
|
| They are automatically set in the view :)These are textboxes:<asp:BoundField DataField="SalgID" HeaderText="SalgID" InsertVisible="false" ReadOnly="true" /><asp:BoundField DataField="Dato" HeaderText="Dato" /><asp:BoundField DataField="Antall" HeaderText="Antall" /><asp:BoundField DataField="Omsetning" HeaderText="Omsetning" />Everything you write into them will be sendt and stored to the database,if you have a insert button and the datasource is connected to the view.You have to do this in design and taskmenu. |
 |
|
|
|
|
|
|
|