ASP.NET - FormView error: Must declare the variable '@WorkOrderID'

Asked By Diana Ansari on 24-Apr-11 02:07 PM

Can someone help me on the issue I am having

I am using Visual 2010 with c# programming language and sql server 2008 R2


When I try to insert, update, or delete. I get the same error message when I debug:

Must declare the variable '@WorkOrderID'.


Here is the aspx code for the INSERT command

<%@ Page Language="C#"  AutoEventWireup="true" CodeBehind="CreateWorkOrder.aspx.cs" Inherits="Capstone.CreateWorkOrder" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

    <head id="Head1" runat="server">

    <title>Work Order</title>
    <style type="text/css">
      .style1
      {
        width: 756px;
        height: 78px;
      }
    </style>
    </head>
<body>
  <form id="form1" runat="server">
    <img alt="" class="style1" src="Styles/skuselector2[1].gif" /><br />
    <br />

    <br />
    Customer Information<br />
    <br />

 
    <asp:FormView ID="FormViewCreate" runat="server" CellPadding="4"
      ForeColor="#333333" DataSourceID="SqlDataSource1" DataKeyNames="WorkOrderID, Name, Address, City, State, ZipCode">
      <EditItemTemplate>
        WorkOrderID:
        <asp:TextBox ID="WorkOrderIDTextBox" runat="server"
          Text='<%# Bind("WorkOrderID") %>' />
        <br />
        Name:
        <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
        <br />
        Address:
        <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
        <br />
        City:
        <asp:TextBox ID="CityTextBox" runat="server" Text='<%# Bind("City") %>' />
        <br />
        State:
        <asp:TextBox ID="StateTextBox" runat="server" Text='<%# Bind("State") %>' />
        <br />
        ZipCode:
        <asp:TextBox ID="ZipCodeTextBox" runat="server" Text='<%# Bind("ZipCode") %>' />
        <br />
        Phone:
        <asp:TextBox ID="PhoneTextBox" runat="server" Text='<%# Bind("Phone") %>' />
        <br />
        DueDate:
        <asp:TextBox ID="DueDateTextBox" runat="server" Text='<%# Bind("DueDate") %>' />
        <br />
        EmployeeName:
        <asp:TextBox ID="EmployeeNameTextBox" runat="server"
          Text='<%# Bind("EmployeeName") %>' />
        <br />
        Copies:
        <asp:TextBox ID="CopiesTextBox" runat="server" Text='<%# Bind("Copies") %>'></asp:TextBox>
        <br />
        PaperSize:
        <asp:TextBox ID="PaperSizeTextBox" runat="server"
          Text='<%# Bind("PaperSize") %>' />
        <br />
        PaperCode:
        <asp:TextBox ID="PaperCodeTextBox" runat="server"
          Text='<%# Bind("PaperCode") %>' />
        <br />
        Sides:
        <asp:TextBox ID="SidesTextBox" runat="server" Text='<%# Bind("Sides") %>' />
        <br />
        Binding:
        <asp:TextBox ID="BindingTextBox" runat="server" Text='<%# Bind("Binding") %>' />
        <br />
        BindingCover:
        <asp:TextBox ID="BindingCoverTextBox" runat="server"
          Text='<%# Bind("BindingCover") %>' />
        <br />
        Staples:
        <asp:TextBox ID="StaplesTextBox" runat="server" Text='<%# Bind("Staples") %>' />
        <br />
        Folding:
        <asp:TextBox ID="FoldingTextBox" runat="server" Text='<%# Bind("Folding") %>' />
        <br />
        DesktopPublishing:
        <asp:TextBox ID="DesktopPublishingTextBox" runat="server"
          Text='<%# Bind("DesktopPublishing") %>' />
        <br />
        WorkNotes:
        <asp:TextBox ID="WorkNotesTextBox" runat="server"
          Text='<%# Bind("WorkNotes") %>' />
        <br />
        <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
          CommandName="Update" Text="Update" />
        &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server"
          CausesValidation="False" CommandName="Cancel" Text="Cancel" />
      </EditItemTemplate>
      <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
      <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
      <InsertItemTemplate>
        WorkOrderID:
        <asp:TextBox ID="WorkOrderIDTextBox" runat="server"
          Text='<%# Bind("WorkOrderID") %>' />
        <br />
        Name:
        <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
        <br />
        Address:
        <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
        <br />
        City:
        <asp:TextBox ID="CityTextBox" runat="server" Text='<%# Bind("City") %>' />
        <br />
        State:
        <asp:TextBox ID="StateTextBox" runat="server" Text='<%# Bind("State") %>' />
        <br />
        ZipCode:
        <asp:TextBox ID="ZipCodeTextBox" runat="server" Text='<%# Bind("ZipCode") %>' />
        <br />
        Phone:
        <asp:TextBox ID="PhoneTextBox" runat="server" Text='<%# Bind("Phone") %>' />
        <br />
        DueDate:
        <asp:TextBox ID="DueDateTextBox" runat="server" Text='<%# Bind("DueDate") %>' />
        <br />
        EmployeeName:
        <asp:TextBox ID="EmployeeNameTextBox" runat="server"
          Text='<%# Bind("EmployeeName") %>' />
        <br />
        Copies:
        <asp:TextBox ID="CopiesTextBox" runat="server" Text='<%# Bind("Copies") %>'></asp:TextBox>
        <br />
        PaperSize:
        <asp:TextBox ID="PaperSizeTextBox" runat="server"
          Text='<%# Bind("PaperSize") %>' />
         
        <br />
        PaperCode:
        <asp:TextBox ID="PaperCodeTextBox" runat="server"
          Text='<%# Bind("PaperCode") %>' />
        <br />
        Sides:
        <asp:TextBox ID="SidesTextBox" runat="server" Text='<%# Bind("Sides") %>' />
        <br />
        Binding:
        <asp:TextBox ID="BindingTextBox" runat="server" Text='<%# Bind("Binding") %>' />
        <br />
        BindingCover:
        <asp:TextBox ID="BindingCoverTextBox" runat="server"
          Text='<%# Bind("BindingCover") %>' />
        <br />
        Staples:
        <asp:TextBox ID="StaplesTextBox" runat="server" Text='<%# Bind("Staples") %>' />
        <br />
        Folding:
        <asp:TextBox ID="FoldingTextBox" runat="server" Text='<%# Bind("Folding") %>' />
        <br />
        DesktopPublishing:
        <asp:TextBox ID="DesktopPublishingTextBox" runat="server"
          Text='<%# Bind("DesktopPublishing") %>' />
        <br />
        WorkNotes:&nbsp;<asp:TextBox ID="WorkNotesTextBox" runat="server"
          Text='<%# Bind("WorkNotes") %>' />
        <br />
        <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
          CommandName="Insert" Text="Insert" />
        &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server"
          CausesValidation="False" CommandName="Cancel" Text="Cancel" />
      </InsertItemTemplate>
      <ItemTemplate>
        WorkOrderID:
        <asp:Label ID="WorkOrderIDLabel" runat="server"
          Text='<%# Bind("WorkOrderID") %>' />
        <br />
        Name:
        <asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>' />
        <br />
        Address:
        <asp:Label ID="AddressLabel" runat="server" Text='<%# Bind("Address") %>' />
        <br />
        City:
        <asp:Label ID="CityLabel" runat="server" Text='<%# Bind("City") %>' />
        <br />
        State:
        <asp:Label ID="StateLabel" runat="server" Text='<%# Bind("State") %>' />
        <br />
        ZipCode:
        <asp:Label ID="ZipCodeLabel" runat="server" Text='<%# Bind("ZipCode") %>' />
        <br />
        Phone:
        <asp:Label ID="PhoneLabel" runat="server" Text='<%# Bind("Phone") %>' />
        <br />
        DueDate:
        <asp:Label ID="DueDateLabel" runat="server" Text='<%# Bind("DueDate") %>' />
        <br />
        EmployeeName:
        <asp:Label ID="EmployeeNameLabel" runat="server"
          Text='<%# Bind("EmployeeName") %>' />
        <br />
        Copies:
        <asp:Label ID="CopiesLabel" runat="server" Text='<%# Bind("Copies") %>' />
        <br />
        PaperSize:
        <asp:Label ID="PaperSizeLabel" runat="server" Text='<%# Bind("PaperSize") %>' />
        <br />
        PaperCode:
        <asp:Label ID="PaperCodeLabel" runat="server" Text='<%# Bind("PaperCode") %>' />
        <br />
        Sides:
        <asp:Label ID="SidesLabel" runat="server" Text='<%# Bind("Sides") %>' />
        <br />
        Binding:
        <asp:Label ID="BindingLabel" runat="server" Text='<%# Bind("Binding") %>' />
        <br />
        BindingCover:
        <asp:Label ID="BindingCoverLabel" runat="server"
          Text='<%# Bind("BindingCover") %>' />
        <br />
        Staples:
        <asp:Label ID="StaplesLabel" runat="server" Text='<%# Bind("Staples") %>' />
        <br />
        Folding:
        <asp:Label ID="FoldingLabel" runat="server" Text='<%# Bind("Folding") %>' />
        <br />
        DesktopPublishing:
        <asp:Label ID="DesktopPublishingLabel" runat="server"
          Text='<%# Bind("DesktopPublishing") %>' />
        <br />
        WorkNotes:
        <asp:Label ID="WorkNotesLabel" runat="server" Text='<%# Bind("WorkNotes") %>' />
        <br />
        <asp:LinkButton ID="btnSubmit" runat="server" CausesValidation="False"
          CommandName="New" Text="New" />
      </ItemTemplate>
      <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
      <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
    </asp:FormView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
      ConnectionString="<%$ ConnectionStrings:ConnectionString3 %>"
      InsertCommand="INSERT INTO [Customer]  ([WorkOrderID], [Name], [Address], [City], [State], [ZipCode], [Phone], [DueDate], [EmployeeName],  [Copies], [PaperSize], [PaperCode], [Sides], [Binding], [BindingCover], [Staples], [Folding], [DesktopPublishing]) VALUES (@WorkOrderID, @Name, @Address, @City, @State, @ZipCode, @DueDate, @EmployeeName, @Copies, @PaperSize, @PaperCode, @Sides, @Binding, @BindingCover, @Staples, @Folding, @DesktopPublishing)"
      ProviderName="<%$ ConnectionStrings:ConnectionString3.ProviderName %>"
      
      SelectCommand="SELECT WorkOrderID, Name, Address, City, State, ZipCode, Phone, DueDate, EmployeeName, Copies, PaperSize, PaperCode, Sides, Binding, BindingCover, Staples, Folding, DesktopPublishing, WorkNotes FROM dansari.dbo.Customer INNER JOIN dansari.dbo.WorkOrder ON Customer.CustomerID = WorkOrder.CustomerID">
    
      <InsertParameters>
        <asp:Parameter Name="WorkOrderID" Type="Int32" />
        <asp:Parameter Name="Name" Type="String"  />
        <asp:Parameter Name="Address" Type="String" />
        <asp:Parameter Name="City" Type="String" />
        <asp:Parameter Name="State" Type="String" />
        <asp:Parameter Name="ZipCode" Type="String" />
        <asp:Parameter Name="Copies" Type="String" />
        <asp:Parameter Name="PaperSize" Type="String" />
        <asp:Parameter Name="PaperCode" Type="String" />
        <asp:Parameter Name="Sides" Type="String" />
      </InsertParameters>

    </asp:SqlDataSource>
    </form>
    </body>
</html>
Peter Bromberg replied to Diana Ansari on 24-Apr-11 04:51 PM
Is "WorkOrderId" an Identity column in your SQL Server table? If so, it would be generated automatically on an INSERT and so that column and the accompanying parameter would not be used.
Diana Ansari replied to Diana Ansari on 24-Apr-11 05:58 PM
I tried what you suggested and I still get an error.

This is the code that I am working with now.

<%@ Page Language="C#"  AutoEventWireup="true" CodeBehind="CreateWorkOrder.aspx.cs" Inherits="Capstone.CreateWorkOrder" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

    <head id="Head1" runat="server">

    <title>Work Order</title>
    <style type="text/css">
      .style1
      {
        width: 756px;
        height: 78px;
      }
    </style>
    </head>
<body>
  <form id="form1" runat="server">
    <img alt="" class="style1" src="Styles/skuselector2[1].gif" /><br />
    <br />

    <br />
    Customer Information<br />
    <br />

 
    <asp:FormView ID="FormViewCreate" runat="server" CellPadding="4"
      ForeColor="#333333" DataSourceID="SqlDataSource1" DataKeyNames="WorkOrderID, Name, Address, City, State, ZipCode">
      <EditItemTemplate>
        WorkOrderID:
        <asp:TextBox ID="WorkOrderIDTextBox" runat="server"
          Text='<%# Bind("WorkOrderID") %>' />
        <br />
        Name:
        <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
        <br />
        Address:
        <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
        <br />
        City:
        <asp:TextBox ID="CityTextBox" runat="server" Text='<%# Bind("City") %>' />
        <br />
        State:
        <asp:TextBox ID="StateTextBox" runat="server" Text='<%# Bind("State") %>' />
        <br />
        ZipCode:
        <asp:TextBox ID="ZipCodeTextBox" runat="server" Text='<%# Bind("ZipCode") %>' />
        <br />
        Phone:
        <asp:TextBox ID="PhoneTextBox" runat="server" Text='<%# Bind("Phone") %>' />
        <br />
        DueDate:
        <asp:TextBox ID="DueDateTextBox" runat="server" Text='<%# Bind("DueDate") %>' />
        <br />
        EmployeeName:
        <asp:TextBox ID="EmployeeNameTextBox" runat="server"
          Text='<%# Bind("EmployeeName") %>' />
        <br />
        Copies:
        <asp:TextBox ID="CopiesTextBox" runat="server" Text='<%# Bind("Copies") %>'></asp:TextBox>
        <br />
        PaperSize:
        <asp:TextBox ID="PaperSizeTextBox" runat="server"
          Text='<%# Bind("PaperSize") %>' />
        <br />
        PaperCode:
        <asp:TextBox ID="PaperCodeTextBox" runat="server"
          Text='<%# Bind("PaperCode") %>' />
        <br />
        Sides:
        <asp:TextBox ID="SidesTextBox" runat="server" Text='<%# Bind("Sides") %>' />
        <br />
        Binding:
        <asp:TextBox ID="BindingTextBox" runat="server" Text='<%# Bind("Binding") %>' />
        <br />
        BindingCover:
        <asp:TextBox ID="BindingCoverTextBox" runat="server"
          Text='<%# Bind("BindingCover") %>' />
        <br />
        Staples:
        <asp:TextBox ID="StaplesTextBox" runat="server" Text='<%# Bind("Staples") %>' />
        <br />
        Folding:
        <asp:TextBox ID="FoldingTextBox" runat="server" Text='<%# Bind("Folding") %>' />
        <br />
        DesktopPublishing:
        <asp:TextBox ID="DesktopPublishingTextBox" runat="server"
          Text='<%# Bind("DesktopPublishing") %>' />
        <br />
        WorkNotes:
        <asp:TextBox ID="WorkNotesTextBox" runat="server"
          Text='<%# Bind("WorkNotes") %>' />
        <br />
        <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
          CommandName="Update" Text="Update" />
        &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server"
          CausesValidation="False" CommandName="Cancel" Text="Cancel" />
      </EditItemTemplate>
      <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
      <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
      <InsertItemTemplate>
        WorkOrderID:
        <asp:TextBox ID="WorkOrderIDTextBox" runat="server"
          Text='<%# Bind("WorkOrderID") %>' />
        <br />
        Name:
        <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
        <br />
        Address:
        <asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />
        <br />
        City:
        <asp:TextBox ID="CityTextBox" runat="server" Text='<%# Bind("City") %>' />
        <br />
        State:
        <asp:TextBox ID="StateTextBox" runat="server" Text='<%# Bind("State") %>' />
        <br />
        ZipCode:
        <asp:TextBox ID="ZipCodeTextBox" runat="server" Text='<%# Bind("ZipCode") %>' />
        <br />
        Phone:
        <asp:TextBox ID="PhoneTextBox" runat="server" Text='<%# Bind("Phone") %>' />
        <br />
        DueDate:
        <asp:TextBox ID="DueDateTextBox" runat="server" Text='<%# Bind("DueDate") %>' />
        <br />
        EmployeeName:
        <asp:TextBox ID="EmployeeNameTextBox" runat="server"
          Text='<%# Bind("EmployeeName") %>' />
        <br />
        Copies:
        <asp:TextBox ID="CopiesTextBox" runat="server" Text='<%# Bind("Copies") %>'></asp:TextBox>
        <br />
        PaperSize:
        <asp:TextBox ID="PaperSizeTextBox" runat="server"
          Text='<%# Bind("PaperSize") %>' />
         
        <br />
        PaperCode:
        <asp:TextBox ID="PaperCodeTextBox" runat="server"
          Text='<%# Bind("PaperCode") %>' />
        <br />
        Sides:
        <asp:TextBox ID="SidesTextBox" runat="server" Text='<%# Bind("Sides") %>' />
        <br />
        Binding:
        <asp:TextBox ID="BindingTextBox" runat="server" Text='<%# Bind("Binding") %>' />
        <br />
        BindingCover:
        <asp:TextBox ID="BindingCoverTextBox" runat="server"
          Text='<%# Bind("BindingCover") %>' />
        <br />
        Staples:
        <asp:TextBox ID="StaplesTextBox" runat="server" Text='<%# Bind("Staples") %>' />
        <br />
        Folding:
        <asp:TextBox ID="FoldingTextBox" runat="server" Text='<%# Bind("Folding") %>' />
        <br />
        DesktopPublishing:
        <asp:TextBox ID="DesktopPublishingTextBox" runat="server"
          Text='<%# Bind("DesktopPublishing") %>' />
        <br />
        WorkNotes:&nbsp;<asp:TextBox ID="WorkNotesTextBox" runat="server"
          Text='<%# Bind("WorkNotes") %>' />
        <br />
        <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
          CommandName="Insert" Text="Insert" />
        &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server"
          CausesValidation="False" CommandName="Cancel" Text="Cancel" />
      </InsertItemTemplate>
      <ItemTemplate>
        WorkOrderID:
        <asp:Label ID="WorkOrderIDLabel" runat="server"
          Text='<%# Bind("WorkOrderID") %>' />
        <br />
        Name:
        <asp:Label ID="NameLabel" runat="server" Text='<%# Bind("Name") %>' />
        <br />
        Address:
        <asp:Label ID="AddressLabel" runat="server" Text='<%# Bind("Address") %>' />
        <br />
        City:
        <asp:Label ID="CityLabel" runat="server" Text='<%# Bind("City") %>' />
        <br />
        State:
        <asp:Label ID="StateLabel" runat="server" Text='<%# Bind("State") %>' />
        <br />
        ZipCode:
        <asp:Label ID="ZipCodeLabel" runat="server" Text='<%# Bind("ZipCode") %>' />
        <br />
        Phone:
        <asp:Label ID="PhoneLabel" runat="server" Text='<%# Bind("Phone") %>' />
        <br />
        DueDate:
        <asp:Label ID="DueDateLabel" runat="server" Text='<%# Bind("DueDate") %>' />
        <br />
        EmployeeName:
        <asp:Label ID="EmployeeNameLabel" runat="server"
          Text='<%# Bind("EmployeeName") %>' />
        <br />
        Copies:
        <asp:Label ID="CopiesLabel" runat="server" Text='<%# Bind("Copies") %>' />
        <br />
        PaperSize:
        <asp:Label ID="PaperSizeLabel" runat="server" Text='<%# Bind("PaperSize") %>' />
        <br />
        PaperCode:
        <asp:Label ID="PaperCodeLabel" runat="server" Text='<%# Bind("PaperCode") %>' />
        <br />
        Sides:
        <asp:Label ID="SidesLabel" runat="server" Text='<%# Bind("Sides") %>' />
        <br />
        Binding:
        <asp:Label ID="BindingLabel" runat="server" Text='<%# Bind("Binding") %>' />
        <br />
        BindingCover:
        <asp:Label ID="BindingCoverLabel" runat="server"
          Text='<%# Bind("BindingCover") %>' />
        <br />
        Staples:
        <asp:Label ID="StaplesLabel" runat="server" Text='<%# Bind("Staples") %>' />
        <br />
        Folding:
        <asp:Label ID="FoldingLabel" runat="server" Text='<%# Bind("Folding") %>' />
        <br />
        DesktopPublishing:
        <asp:Label ID="DesktopPublishingLabel" runat="server"
          Text='<%# Bind("DesktopPublishing") %>' />
        <br />
        WorkNotes:
        <asp:Label ID="WorkNotesLabel" runat="server" Text='<%# Bind("WorkNotes") %>' />
        <br />
        <asp:LinkButton ID="btnSubmit" runat="server" CausesValidation="False"
          CommandName="New" Text="New" />
      </ItemTemplate>
      <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
      <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
    </asp:FormView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
      ConnectionString="<%$ ConnectionStrings:ConnectionString3 %>"
      InsertCommand="INSERT INTO [Customer]  ([Name], [Address], [City], [State], [ZipCode], [Phone], [DueDate], [EmployeeName],  [Copies], [PaperSize], [PaperCode], [Sides], [Binding], [BindingCover], [Staples], [Folding], [DesktopPublishing]) VALUES (@WorkOrderID, @Name, @Address, @City, @State, @ZipCode, @DueDate, @EmployeeName, @Copies, @PaperSize, @PaperCode, @Sides, @Binding, @BindingCover, @Staples, @Folding, @DesktopPublishing)"
      ProviderName="<%$ ConnectionStrings:ConnectionString3.ProviderName %>"
      
      SelectCommand="SELECT Name, Address, City, State, ZipCode, Phone, DueDate, EmployeeName, Copies, PaperSize, PaperCode, Sides, Binding, BindingCover, Staples, Folding, DesktopPublishing, WorkNotes FROM dansari.dbo.Customer INNER JOIN dansari.dbo.WorkOrder ON Customer.CustomerID = WorkOrder.CustomerID">
    
      <InsertParameters>
        <asp:Parameter Name="Name" Type="String"  />
        <asp:Parameter Name="Address" Type="String" />
        <asp:Parameter Name="City" Type="String" />
        <asp:Parameter Name="State" Type="String" />
        <asp:Parameter Name="ZipCode" Type="String" />
        <asp:Parameter Name="Copies" Type="String" />
        <asp:Parameter Name="PaperSize" Type="String" />
        <asp:Parameter Name="PaperCode" Type="String" />
        <asp:Parameter Name="Sides" Type="String" />
      </InsertParameters>

    </asp:SqlDataSource>
    </form>
    </body>
</html>
Diana Ansari replied to Peter Bromberg on 24-Apr-11 06:00 PM
Before I have put in workorderID insert, I had the same error but with @Name.
Nikhil Mahajan replied to Diana Ansari on 24-Apr-11 09:01 PM
hi,,

you are getting this error because you are not passing same variable in insert statement...

i mean in your insert statement.. you are inserting in customer table  a phone parameter... but you are not passing its value.... its the first error....
2nd thing is you are not inserting workorderID but you are passing its value.........so that is error no 2..

  InsertCommand="INSERT INTO [Customer]  ([Name], [Address], [City], [State], [ZipCode], [Phone], [DueDate], [EmployeeName],  [Copies], [PaperSize], [PaperCode], [Sides], [Binding], [BindingCover], [Staples], [Folding], [DesktopPublishing]) VALUES (@WorkOrderID, @Name, @Address, @City, @State, @ZipCode, @DueDate, @EmployeeName, @Copies, @PaperSize, @PaperCode, @Sides, @Binding, @BindingCover, @Staples, @Folding, @DesktopPublishing)"
    ProviderName="<%$ ConnectionStrings:ConnectionString3.ProviderName %>"

Instead of above query use below insert query....

InsertCommand="INSERT INTO [Customer]  ([Name], [Address], [City], [State], [ZipCode], [Phone], [DueDate], [EmployeeName],  [Copies], [PaperSize], [PaperCode], [Sides], [Binding], [BindingCover], [Staples], [Folding], [DesktopPublishing]) VALUES (@Name, @Address, @City, @State, @ZipCode, @Phone, @DueDate, @EmployeeName, @Copies, @PaperSize, @PaperCode, @Sides, @Binding, @BindingCover, @Staples, @Folding, @DesktopPublishing)"
    ProviderName="<%$ ConnectionStrings:ConnectionString3.ProviderName %>"
Diana Ansari replied to Diana Ansari on 24-Apr-11 09:16 PM
Now I am getting an error that says

Must declare the variable '@WorkOrderID'

Here is the updated code

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CreateWorkOrder.aspx.cs" Inherits="Capstone.CreateWorkOrder" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head id="Head1" runat="server">

<title>Work Order</title>

<style type="text/css">

.style1

{

width: 756px;

height: 78px;

}

</style>

</head>

<body>

<form id="form1" runat="server">

<img alt="" class="style1" src="Styles/skuselector2[1].gif" /><br />

<br />

<br />

Customer Information<br />

<br />


<asp:FormView ID="FormViewCreate" runat="server" CellPadding="4"

ForeColor="#333333" DataSourceID="SqlDataSource1">

<EditItemTemplate>

Name:

<asp:TextBox ID="NameTextBox" runat="server"

Text='<%# Bind("Name") %>' />

<br />

Address:

<asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />

<br />

City:

<asp:TextBox ID="CityTextBox" runat="server" Text='<%# Bind("City") %>' />

<br />

State:

<asp:TextBox ID="StateTextBox" runat="server" Text='<%# Bind("State") %>' />

<br />

ZipCode:

<asp:TextBox ID="ZipCodeTextBox" runat="server" Text='<%# Bind("ZipCode") %>' />

<br />

Phone:

<asp:TextBox ID="PhoneTextBox" runat="server" Text='<%# Bind("Phone") %>' />

<br />

DueDate:

<asp:TextBox ID="DueDateTextBox" runat="server" Text='<%# Bind("DueDate") %>' />

<br />

EmployeeName:

<asp:TextBox ID="EmployeeNameTextBox" runat="server"

Text='<%# Bind("EmployeeName") %>' />

<br />

Copies:

<asp:TextBox ID="CopiesTextBox" runat="server"

Text='<%# Bind("Copies") %>' />

<br />

PaperSize:

<asp:TextBox ID="PaperSizeTextBox" runat="server"

Text='<%# Bind("PaperSize") %>'></asp:TextBox>

<br />

PaperCode:

<asp:TextBox ID="PaperCodeTextBox" runat="server"

Text='<%# Bind("PaperCode") %>' />

<br />

Sides:

<asp:TextBox ID="SidesTextBox" runat="server"

Text='<%# Bind("Sides") %>' />

<br />

Binding:

<asp:TextBox ID="BindingTextBox" runat="server" Text='<%# Bind("Binding") %>' />

<br />

BindingCover:

<asp:TextBox ID="BindingCoverTextBox" runat="server"

Text='<%# Bind("BindingCover") %>' />

<br />

Staples:

<asp:TextBox ID="StaplesTextBox" runat="server"

Text='<%# Bind("Staples") %>' />

<br />

Folding:

<asp:TextBox ID="FoldingTextBox" runat="server" Text='<%# Bind("Folding") %>' />

<br />

DesktopPublishing:

<asp:TextBox ID="DesktopPublishingTextBox" runat="server"

Text='<%# Bind("DesktopPublishing") %>' />

<br />

WorkNotes:

<asp:TextBox ID="WorkNotesTextBox" runat="server"

Text='<%# Bind("WorkNotes") %>' />

<br />

<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"

CommandName="Update" Text="Update" />

&nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server"

CausesValidation="False" CommandName="Cancel" Text="Cancel" />

</EditItemTemplate>

<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />

<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />

<InsertItemTemplate>

Name:

<asp:TextBox ID="NameTextBox" runat="server"

Text='<%# Bind("Name") %>' />

<br />

Address:

<asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>' />

<br />

City:

<asp:TextBox ID="CityTextBox" runat="server" Text='<%# Bind("City") %>' />

<br />

State:

<asp:TextBox ID="StateTextBox" runat="server" Text='<%# Bind("State") %>' />

<br />

ZipCode:

<asp:TextBox ID="ZipCodeTextBox" runat="server" Text='<%# Bind("ZipCode") %>' />

<br />

Phone:

<asp:TextBox ID="PhoneTextBox" runat="server" Text='<%# Bind("Phone") %>' />

<br />

DueDate:

<asp:TextBox ID="DueDateTextBox" runat="server" Text='<%# Bind("DueDate") %>' />

<br />

EmployeeName:

<asp:TextBox ID="EmployeeNameTextBox" runat="server"

Text='<%# Bind("EmployeeName") %>' />

<br />

Copies:

<asp:TextBox ID="CopiesTextBox" runat="server"

Text='<%# Bind("Copies") %>' />

<br />

PaperSize:

<asp:TextBox ID="PaperSizeTextBox" runat="server"

Text='<%# Bind("PaperSize") %>'></asp:TextBox>

<br />

PaperCode:

<asp:TextBox ID="PaperCodeTextBox" runat="server"

Text='<%# Bind("PaperCode") %>' />


<br />

Sides:

<asp:TextBox ID="SidesTextBox" runat="server"

Text='<%# Bind("Sides") %>' />

<br />

Binding:

<asp:TextBox ID="BindingTextBox" runat="server" Text='<%# Bind("Binding") %>' />

<br />

BindingCover:

<asp:TextBox ID="BindingCoverTextBox" runat="server"

Text='<%# Bind("BindingCover") %>' />

<br />

Staples:

<asp:TextBox ID="StaplesTextBox" runat="server"

Text='<%# Bind("Staples") %>' />

<br />

Folding:

<asp:TextBox ID="FoldingTextBox" runat="server" Text='<%# Bind("Folding") %>' />

<br />

DesktopPublishing:

<asp:TextBox ID="DesktopPublishingTextBox" runat="server"

Text='<%# Bind("DesktopPublishing") %>' />

<br />

WorkNotes:

<asp:TextBox ID="WorkNotesTextBox" runat="server"

Text='<%# Bind("WorkNotes") %>' />

<br />

<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"

CommandName="Insert" Text="Insert" />

&nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server"

CausesValidation="False" CommandName="Cancel" Text="Cancel" />

</InsertItemTemplate>

<ItemTemplate>

Name:

<asp:Label ID="NameLabel" runat="server"

Text='<%# Bind("Name") %>' />

<br />

Address:

<asp:Label ID="AddressLabel" runat="server" Text='<%# Bind("Address") %>' />

<br />

City:

<asp:Label ID="CityLabel" runat="server" Text='<%# Bind("City") %>' />

<br />

State:

<asp:Label ID="StateLabel" runat="server" Text='<%# Bind("State") %>' />

<br />

ZipCode:

<asp:Label ID="ZipCodeLabel" runat="server" Text='<%# Bind("ZipCode") %>' />

<br />

Phone:

<asp:Label ID="PhoneLabel" runat="server" Text='<%# Bind("Phone") %>' />

<br />

DueDate:

<asp:Label ID="DueDateLabel" runat="server" Text='<%# Bind("DueDate") %>' />

<br />

EmployeeName:

<asp:Label ID="EmployeeNameLabel" runat="server"

Text='<%# Bind("EmployeeName") %>' />

<br />

Copies:

<asp:Label ID="CopiesLabel" runat="server"

Text='<%# Bind("Copies") %>' />

<br />

PaperSize:

<asp:Label ID="PaperSizeLabel" runat="server" Text='<%# Bind("PaperSize") %>' />

<br />

PaperCode:

<asp:Label ID="PaperCodeLabel" runat="server" Text='<%# Bind("PaperCode") %>' />

<br />

Sides:

<asp:Label ID="SidesLabel" runat="server" Text='<%# Bind("Sides") %>' />

<br />

Binding:

<asp:Label ID="BindingLabel" runat="server" Text='<%# Bind("Binding") %>' />

<br />

BindingCover:

<asp:Label ID="BindingCoverLabel" runat="server"

Text='<%# Bind("BindingCover") %>' />

<br />

Staples:

<asp:Label ID="StaplesLabel" runat="server"

Text='<%# Bind("Staples") %>' />

<br />

Folding:

<asp:Label ID="FoldingLabel" runat="server" Text='<%# Bind("Folding") %>' />

<br />

DesktopPublishing:

<asp:Label ID="DesktopPublishingLabel" runat="server"

Text='<%# Bind("DesktopPublishing") %>' />

<br />

WorkNotes:

<asp:Label ID="WorkNotesLabel" runat="server"

Text='<%# Bind("WorkNotes") %>' />

<br />

<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False"

CommandName="New" Text="New" />

</ItemTemplate>

<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />

<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />

</asp:FormView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"

ConnectionString="<%$ ConnectionStrings:ConnectionString3 %>"

InsertCommand="INSERT INTO [Customer] ([Name], [Address], [City], [State], [ZipCode], [Phone], [DueDate], [EmployeeName], [Copies], [PaperSize], [PaperCode], [Sides], [Binding], [BindingCover], [Staples], [Folding], [DesktopPublishing]) VALUES (@Name, @Address, @City, @State, @ZipCode, @Phone, @DueDate, @EmployeeName, @Copies, @PaperSize, @PaperCode, @Sides, @Binding, @BindingCover, @Staples, @Folding, @DesktopPublishing)"

ProviderName="<%$ ConnectionStrings:ConnectionString3.ProviderName %>"


SelectCommand="SELECT Name, Address, City, State, ZipCode, Phone, DueDate, EmployeeName, Copies, PaperSize, PaperCode, Sides, Binding, BindingCover, Staples, Folding, DesktopPublishing, WorkNotes FROM dansari.dbo.Customer INNER JOIN dansari.dbo.WorkOrder ON Customer.CustomerID = WorkOrder.CustomerID">


<InsertParameters>

<asp:Parameter Name="Name" Type="String" />

<asp:Parameter Name="Address" Type="String" />

<asp:Parameter Name="City" Type="String" />

<asp:Parameter Name="State" Type="String" />

<asp:Parameter Name="ZipCode" Type="String" />

<asp:Parameter Name="Copies" Type="String" />

<asp:Parameter Name="PaperSize" Type="String" />

<asp:Parameter Name="PaperCode" Type="String" />

<asp:Parameter Name="Sides" Type="String" />

</InsertParameters>

</asp:SqlDataSource>

</form>

</body>

</html>



This is my SQL tables


Customer

Name Policy Health State
CustomerID (PK, varchar(50), not null) 
Name (char(50), null) 
Address (varchar(50), null) 
City (char(50), null) 
State (char(10), null) 
ZipCode (nchar(10), null) 
Phone (nchar(10), null) 


WorkOrder

Name Policy Health State
WorkOrderID (PK, bigint, not null) 
CustomerID (varchar(50), null) 
DueDate (datetime, null) 
Copies (varchar(50), null) 
PaperSize (varchar(50), null) 
PaperCode (varchar(50), null) 
Sides (varchar(50), null) 
Binding (varchar(50), null) 
BindingCover (varchar(50), null) 
Staples (varchar(50), null) 
Folding (varchar(50), null) 
DesktopPublishing (varchar(50), null) 
EmployeeName (varchar(50), null) 
WorkNotes (varchar(999), null)