0 Replies - 10064 Views - Last Post: 07 June 2012 - 08:32 PM

#1 Musashin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 09-May 07

InsertParameters filling wrong fields in database

Posted 07 June 2012 - 08:32 PM

Hi guys, it's been quite a while since I posted on these forums..

I'm doing a course in web development and having a bit of trouble with the asp.net side of things. I am making a simple shopping cart for an assignment that takes data from a form and adds it as a record in an access database table.

My problem is that it seems to be skipping the first field and adding data starting from the second which is obviously causing all the data to fill the wrong fields, I have no idea why.

vb.net:
Private Sub createInvoice()
        Dim dataSource7 As AccessDataSource = Page.Master.FindControl("AccessDataSource7")

        dataSource7.InsertParameters("CustEmail").DefaultValue = email
        'dataSource7.InsertParameters("CreditCardType").DefaultValue = lbCardType.Text
        dataSource7.InsertParameters("CreditCardType").DefaultValue = lbCardType.SelectedValue
        dataSource7.InsertParameters("CardNumber").DefaultValue = txtCardDetails.Text
        dataSource7.InsertParameters("ExpirationMonth").DefaultValue = ddlMonth.SelectedValue
        dataSource7.InsertParameters("ExpirationYear").DefaultValue = ddlYear.Text
        dataSource7.InsertParameters("orderDate").DefaultValue = Today
        dataSource7.InsertParameters("total").DefaultValue = total
        dataSource7.InsertParameters("subTotal").DefaultValue = subtotal
        dataSource7.InsertParameters("gst").DefaultValue = gst

        dataSource7.Insert()

    End Sub


asp:
<asp:AccessDataSource ID="AccessDataSource7" runat="server" 
                        DataFile="~/App_Data/BooksDB.mdb" 
                        DeleteCommand="DELETE FROM [tblInvoice] WHERE [InvoiceNumber] = ?" 
                        InsertCommand="INSERT INTO [tblInvoice] ([CustEmail], [CreditCardType], [CardNumber], [ExpirationMonth], [ExpirationYear], [orderDate], [total], [subTotal], [gst]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)" 
                        SelectCommand="SELECT * FROM [tblInvoice]" 
                        UpdateCommand="UPDATE [tblInvoice] SET [CustEmail] = ?, [CreditCardType] = ?, [CardNumber] = ?, [ExpirationMonth] = ?, [ExpirationYear] = ?, [orderDate] = ?, [total] = ?, [subTotal] = ?, [gst] = ? WHERE [InvoiceNumber] = ?">
                        <DeleteParameters>
                            <asp:Parameter Name="InvoiceNumber" Type="Int32" />
                        </DeleteParameters>
                        <InsertParameters>
                            <asp:Parameter Name="InvoiceNumber" Type="Int32" />
                            <asp:Parameter Name="CustEmail" Type="String" />
                            <asp:Parameter Name="CreditCardType" Type="String" />
                            <asp:Parameter Name="CardNumber" Type="String" />
                            <asp:Parameter Name="ExpirationMonth" Type="String" />
                            <asp:Parameter Name="ExpirationYear" Type="String" />
                            <asp:Parameter Name="orderDate" Type="String" />
                            <asp:Parameter Name="total" Type="String" />
                            <asp:Parameter Name="subTotal" Type="String" />
                            <asp:Parameter Name="gst" Type="String" />
                        </InsertParameters>
                        <UpdateParameters>
                            <asp:Parameter Name="CustEmail" Type="String" />
                            <asp:Parameter Name="CreditCardType" Type="String" />
                            <asp:Parameter Name="CardNumber" Type="String" />
                            <asp:Parameter Name="ExpirationMonth" Type="String" />
                            <asp:Parameter Name="ExpirationYear" Type="String" />
                            <asp:Parameter Name="orderDate" Type="String" />
                            <asp:Parameter Name="total" Type="String" />
                            <asp:Parameter Name="subTotal" Type="String" />
                            <asp:Parameter Name="gst" Type="String" />
                            <asp:Parameter Name="InvoiceNumber" Type="Int32" />
                        </UpdateParameters>
                    </asp:AccessDataSource>


Here's an image of the record inserted;
http://tinyurl.com/7ubywk9

--

Email is placed in the second field, and so on.

I know this is incredibly basic stuff but I've only been learning asp/vb.net for a few months, and this is the first time I've tried manipulating a database with it. It doesn't help that we're learning this stuff in design view of visual studio (hard to debug when stuff like this happens), I've voiced my concerns about that but he seems adamant that this is the best way.

I would ask my teacher but I don't have class with him for another 5 days, and I've been asking him a lot of stuff lately.. I don't want to detract too much from his time with other students.

If someone could point me in the right direction here that would be great. :-)


Thanks,
Paul.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1