2011-12-09 124 views
0

我目前在Visual Basic 2010中使用webform工作。我在Visual Basic中創建了一個SQL數據庫,並試圖使insert命令將文本框中的值移動到數據庫中。所以我的問題是:我如何從文本框(即:NameTextBox,AddressTextBox ..)獲取值並將它們與參數(@Name,@ Address1)相關聯?ASP.net,SQL數據庫,插入,文本框

該數據庫的工作原理,我通過代碼輸入值來測試它。

下面是相關代碼:

<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> 

回答

0

你參數的名稱屬性是缺少「@」字符。你需要添加它,或者將它看作是一個完全不同的參數。

相關問題