Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 28th, 2006, 07:44 PM
Authorized User
 
Join Date: Feb 2006
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Data inserting twice

I am inserting data from a form using sqldatasource which is connected to a store procedure. My submit has sqldatasource1.Insert in it, now when I click the submit button, the data is getting inserted twice. How can I avoid doing that? I tried without the insert command in the submit button but that does not work. Your help will be much appreciated.
  #2 (permalink)  
Old June 28th, 2006, 11:02 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

what is the code for the button click?

  #3 (permalink)  
Old June 29th, 2006, 12:11 PM
Authorized User
 
Join Date: Feb 2006
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default


I have all the form data assigned to different variables, i.e.
dim straddress as string = txtaddress.text...etc.
(These are added as insert parameters with each form mentioned in the store procedure, in the aspx page)
After I collect all the variables, I have the code:
sqldatasource1.Insert.

Quote:
quote:Originally posted by jbenson001
 what is the code for the button click?

  #4 (permalink)  
Old June 29th, 2006, 03:35 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

So you are assigning values to your parameters from textbox values..etc on the page, then you are calling the insert on the button click, that is all you are doing?

  #5 (permalink)  
Old June 29th, 2006, 05:23 PM
Authorized User
 
Join Date: Feb 2006
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Yes, that is correct. During my research, I also read somewhere that I should put Enable View state for the sqldatasource to be false. I did that also. Any idea why?

Quote:
quote:Originally posted by jbenson001
 So you are assigning values to your parameters from textbox values..etc on the page, then you are calling the insert on the button click, that is all you are doing?

  #6 (permalink)  
Old June 29th, 2006, 10:07 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I can't see why it would Insert twice. Maybe if you post all of the code behind I could find something.

  #7 (permalink)  
Old June 30th, 2006, 11:46 AM
Authorized User
 
Join Date: Feb 2006
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is my code behind:
Partial Class frmEntry
    Inherits System.Web.UI.Page

    Protected Sub InsertData(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

        'main table data collection
        Dim strmeter As String = txtmeter.Text
        Dim straccount As String = CStr(txtAccount.Text)
        Dim dov As String = txtdov.Text
        Dim strsvadd As String = txtsvadd.Text
        Dim strpremise As String = lstpremise.Text
        Dim strcurrentread As String = txtCurrentRead.Text
        Dim strphotos As String = chkPhotos.Text
        Dim strfacts As String = txtFacts.Text
        Dim strbillingname As String = txtbillingName.Text
        Dim strbadd As String = txtbAdd.Text
        Dim strrep As String = txtrep.Text
        Dim strIn As String = txtIn.Text
        Dim uch1, uch2, uch3, uch4, uch5 As Decimal
        Dim q1, q2, q3, q4, q5 As Integer
        Dim sub1, sub2, sub3, sub4, sub5 As Decimal

        Dim customerChg As String = ddchargereason.SelectedValue

        'charges table data collection
        'if the radio button is checked then the corresponsing value is calculated
        If radch1.Checked = True Then
            uch1 = 64.44
            q1 = txtq1.Text
            sub1 = CDec(q1 * uch1)
        Else
            q1 = 0
            sub1 = 0

        End If

        If radch2.Checked = True Then
            uch2 = 10.22
            q2 = txtq2.Text
            sub2 = CDec(q2 * uch2)
        Else
            q2 = 0
            sub2 = 0
        End If

        If radch3.Checked = True Then
            uch3 = 23.85
            q3 = txtq3.Text
            sub3 = CDec(q3 * uch3)
        Else
            q3 = 0
            sub3 = 0
        End If

        If radch4.Checked = True Then
            uch4 = 15.33
            q4 = txtq4.Text
            sub4 = CDec(q4 * uch4)
        Else
            q4 = 0
            sub4 = 0
        End If

        If radch5.Checked = True Then
            uch5 = 34.99

            q5 = txtq5.Text
            sub5 = CDec(q5 * uch5)
        Else
            q5 = 0
            sub5 = 0
        End If
        'collecting all the values of parts charge
        Dim totalcharge As Decimal = CDec((sub1 + sub2 + sub3 + sub4 + sub5))
        'no of hours worked (default is 1)
        Dim hrs As Double = CDbl(txthrs.Text)

        ' If (txtPeople.Text) <> "" Then
        'no of labor (default is 1)
        Dim people As Integer = CInt(txtPeople.Text)
        Dim laborcharge As Decimal
        'total labor charge
        laborcharge = CDec((50.0 * hrs) * people)

        lbltotlabchg.Text = laborcharge
        Dim flatrate As Decimal = (300.0)
        'adding parts and labor
        Dim Grandtotal As Decimal = (totalcharge + laborcharge + flatrate)
        lblgrandtotal.Text = Grandtotal
        'Inserting data
        SqlDataSource2.Insert()

        Response.Write("Data submitted")

    End Sub

    Protected Sub calendar_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles calendar.SelectionChanged
        txtdov.Text = calendar.SelectedDate.ToShortDateString()
        calendar.Visible = False
    End Sub 'Selection_Change

    Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
        calendar.Visible = True
    End Sub
End Class
*******************************************
The aspx source page code that is relevant to the store procedure and parameters:
<InsertParameters>
             <asp:ControlParameter ControlID="txtAccount" DefaultValue="0" Name="ActNumber" PropertyName="Text"
                Type="String" />
            <asp:ControlParameter ControlID="txtmeter" DefaultValue="0" Name="MeterNumber" PropertyName="Text"
                Type="String" />
            <asp:ControlParameter ControlID="txtdov" DefaultValue="" Name="VisitDate" PropertyName="Text"
                Type="DateTime" />
            <asp:ControlParameter ControlID="txtsvadd" DefaultValue="" Name="SvAdd" PropertyName="Text"
                Type="String" />
            <asp:ControlParameter ControlID="txtbillingName" Name="Billing_name" PropertyName="Text"
                Type="String" />
            <asp:ControlParameter ControlID="txtbAdd" Name="billingAdd" PropertyName="Text" Type="String" />
            <asp:ControlParameter ControlID="lstpremise" Name="Premise_Type" PropertyName="SelectedValue"
                Type="String" />
            <asp:ControlParameter ControlID="txtCurrentRead" Name="CurrentRead" PropertyName="Text"
                Type="String" />
            <asp:ControlParameter ControlID="txtFacts" Name="Statement" PropertyName="Text" Type="String" />
            <asp:ControlParameter ControlID="chkPhotos" Name="photos_taken" PropertyName="Checked"
                Type="String" />
            <asp:ControlParameter ControlID="txtrep" Name="Reported" PropertyName="Text" Type="String" />
            <asp:ControlParameter ControlID="txtIn" Name="Investigated" PropertyName="Text" Type="String" />
            <asp:Parameter Name="TampId2" Type="Int32" />
            <asp:ControlParameter ControlID="ddchargereason" DefaultValue="" Name="chargereason"
                PropertyName="SelectedValue" Type="String" />
            <asp:ControlParameter ControlID="radch1" DefaultValue="64.44" Name="charge1" PropertyName="Checked"
                Type="Decimal" />
            <asp:ControlParameter ControlID="txtq1" DefaultValue="" Name="quantity1" PropertyName="Text"
                Type="Int32" />
            <asp:Parameter Name="subtotal1" Type="Decimal" />
            <asp:ControlParameter ControlID="radch2" DefaultValue="10.22" Name="charge2" PropertyName="Checked"
                Type="Decimal" />
            <asp:ControlParameter ControlID="txtq2" DefaultValue="" Name="quantity2" PropertyName="Text"
                Type="Int32" />
            <asp:Parameter Name="subtotal2" Type="Decimal" />
and so on-----
***********************************
thanks for trying to help...I really appreciate it.
  #8 (permalink)  
Old June 30th, 2006, 03:04 PM
Authorized User
 
Join Date: Feb 2006
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello there,
I finally found a way to solve the problem, I looked at the form properties and the "submit disabled controls" was set to true, I changed it to false and it worked...!!!
thanks for trying to help me. Hopefully anyone else struggling with this will be able to see this solution.

Quote:
quote:Originally posted by jbenson001
 I can't see why it would Insert twice. Maybe if you post all of the code behind I could find something.

  #9 (permalink)  
Old August 22nd, 2006, 11:01 AM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm encountering the same issue now except I'm not sure why. I set the submit disabled controls to false but nothing. Here is my entire code:

<%@ Page EnableEventValidation="false" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default3.aspx.vb" Inherits="Default3" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="mainContent" Runat="Server">
<form id="form1" submitdisabledcontrols=false>
    <br />
    <asp:Label ID="Label1" runat="server">Name</asp:Label>
    <asp:TextBox ID="NameTextBox" runat="server"></asp:TextBox>
        <br />
        <br />
    <asp:Label ID="Label2" runat="server" Text="Label">Number</asp:Label>
    <asp:TextBox ID="NumberTextBox" runat="server"></asp:TextBox>
        <br />
        <br />
    <asp:Label ID="Label3" runat="server" Text="Label">Salary</asp:Label>
    <asp:TextBox ID="SalaryTextBox" runat="server"></asp:TextBox>&nbsp;
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_click" />
    </form>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:pubsConnectionString1 %>" DeleteCommand="DELETE FROM [Table1] WHERE [TableID] = @original_TableID" InsertCommand="INSERT INTO [Table1] ([Name], [Number], [Salary]) VALUES (@Name, @Number, @Salary)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [Table1]" UpdateCommand="UPDATE [Table1] SET [Name] = @Name, [Number] = @Number, [Salary] = @Salary WHERE [TableID] = @original_TableID">
        <DeleteParameters>
            <asp:Parameter Name="original_TableID" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="Name" Type="String" />
            <asp:Parameter Name="Number" Type="String" />
            <asp:Parameter Name="Salary" Type="Decimal" />
            <asp:Parameter Name="original_TableID" Type="Int32" />
        </UpdateParameters>

        <InsertParameters>
            <asp:ControlParameter Name="Name" Type="String" ControlID="NameTextBox" />
            <asp:ControlParameter Name="Number" Type="String" ControlID="NumberTextBox" />
            <asp:ControlParameter Name="Salary" Type="decimal" ControlID="SalaryTextBox" />
        </InsertParameters>

    </asp:SqlDataSource>


</asp:Content>


The Button1_Click sub basically runs "SqlDataSource1.Insert()"

Any ideas?

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
inserting data stevens ADO.NET 0 May 13th, 2008 07:49 AM
Inserting data when data already exsist desireemm SQL Language 0 January 16th, 2006 11:01 PM
Inserting data into 2 tables chrscote Access ASP 1 August 1st, 2005 09:01 AM



All times are GMT -4. The time now is 12:20 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.