user1024957
user1024957

Reputation: 1

ASP.net, SQL database, Insert, TextBoxes

I am currently working in Visual Basic 2010 with a webform. I created an SQL database inside of Visual Basic and I'm trying to make the insert command move values from the textboxes into the database.

So my question is: how do I get the values from the textboxes (i.e:NameTextBox, AddressTextBox..) and associate them with the parameters (@Name, @Address1)?

The database works, I tested it by inputing values through the code.

Here is the relevant code:

  <script runat="server">
' InsertShipper
  Private Sub InsertShipper (ByVal Source As Object, ByVal e As EventArgs)
    SqlDataSource1.Insert()
 End Sub
   </script>


 <asp:Button ID="OrderButton" runat="server" onclick="InsertShipper" Text="Order" />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:OrderListConnectionString %>" 
        DeleteCommand="DELETE FROM [ORDER] WHERE [OID] = @OID" 
        InsertCommand="INSERT INTO [ORDER] ([Name], [Address1], [Address2], [City],     [State], [Zip], [Phone], [Email], [Subtotal], [Shipping]) VALUES ( @Name, @Address1,      @Address2, @City, @State, @Zip, @Phone, @Email, @Subtotal, @Shipping)" 
        SelectCommand="SELECT * FROM [ORDER]" 

        UpdateCommand="UPDATE [ORDER] SET [Name] = @Name, [Address1] = @Address1, [Address2] = @Address2, [City] = @City, [State] = @State, [Zip] = @Zip, [Phone] = @Phone, [Email] = @Email, [Subtotal] = @Subtotal, [Shipping] = @Shipping WHERE [OID] = @OID">
        <DeleteParameters>
            <asp:Parameter Name="OID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>

            <asp:Parameter name="Name" Type="String" />
            <asp:Parameter name="Address1" Type="String" />
            <asp:Parameter Name="Address2" Type="String" />
            <asp:Parameter Name="City" Type="String" />
            <asp:Parameter Name="State" Type="String" />
            <asp:Parameter Name="Zip" Type="String" />
            <asp:Parameter Name="Phone" Type="String" />
            <asp:Parameter Name="Email" Type="String" />
            <asp:Parameter Name="Subtotal" Type="String" />
            <asp:Parameter Name="Shipping" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="Name" Type="String" />
            <asp:Parameter Name="Address1" Type="String" />
            <asp:Parameter Name="Address2" Type="String" />
            <asp:Parameter Name="City" Type="String" />
            <asp:Parameter Name="State" Type="String" />
            <asp:Parameter Name="Zip" Type="String" />
            <asp:Parameter Name="Phone" Type="String" />
            <asp:Parameter Name="Email" Type="String" />
            <asp:Parameter Name="Subtotal" Type="String" />
            <asp:Parameter Name="Shipping" Type="String" />
            <asp:Parameter Name="OID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>

Upvotes: 0

Views: 1083

Answers (2)

gsirianni
gsirianni

Reputation: 1364

Your parameters' Name property are missing the "@" character. You need to add this or it sees it as a completely different parameter.

Upvotes: 0

user895400
user895400

Reputation: 368

Try setting the parameters' ControlID and PropertyName as such:

  <asp:ControlParameter Name="Title" 
  ControlID="txtFoo"
  PropertyName="Text"/>

Refer to http://msdn.microsoft.com/en-us/library/xt50s8kz.aspx

Upvotes: 1

Related Questions