Hi All,

Below is the code that I have tried to implement but it always returns "Must Declare the scalar variable "@EmployeeNo". I have gone through the code countless times but I can't figure out what is wrong.

vb Code:
  1. <%@ Page Language="vb" %>
  2. <%@ Import Namespace="System"  %>
  3. <%@ Import Namespace="System.IO" %>
  4. <%@ Import Namespace="System.Data" %>
  5. <%@ Import Namespace="System.Data.OleDb" %>
  6. <%@ Import Namespace="System.Web.UI.WebControls" %>
  7. <%@ Import Namespace="System.Configuration" %>
  8. <%@ Import Namespace="System.Threading" %>
  9. <%@ Import Namespace="System.Globalization" %>
  10. <%@ Import Namespace="System.IO" %>
  11.  
  12. <HTML>
  13.  
  14. <HEAD>
  15.  
  16. <title>Add Employee To Database</title>
  17.  
  18. <script runat=server>
  19.  
  20.                         Public Sub AddPerson(sender As Object, e As EventArgs)
  21.  
  22.  
  23.  
  24.                                     Dim intImageSize As Int64
  25.  
  26.                                     Dim strImageType As String
  27.                                     Dim ImageStream As Stream
  28.  
  29.  
  30.  
  31.                                     ' Gets the Size of the Image
  32.  
  33.                                     intImageSize = PersonImage.PostedFile.ContentLength
  34.  
  35.                                    
  36.  
  37.                                     ' Gets the Image Type
  38.  
  39.                                     strImageType = PersonImage.PostedFile.ContentType
  40.  
  41.                                    
  42.  
  43.                                     ' Reads the Image
  44.  
  45.                                     ImageStream = PersonImage.PostedFile.InputStream
  46.  
  47.  
  48.  
  49.                                     Dim ImageContent(intImageSize) As Byte
  50.  
  51.                                     Dim intStatus As Integer
  52.  
  53.                                     intStatus = ImageStream.Read(ImageContent, 0, intImageSize)
  54.  
  55.  
  56.  
  57.                                     ' Create Instance of Connection and Command Object
  58.  
  59.  
  60.                                     Dim connStr As String = "Provider=SQLOLEDB;Data Source=WIN2K3R2EE\SQLEXPRESS;Initial Catalog=EmployeeDB;User id=;Password="
  61.                                     Dim SQLInsert As String = "INSERT INTO STAFF (EmployeeNo, GivenName, Surname, Telephone, Email, Picture, WrkGrp, SectionID, Gender) VALUES (@EmployeeNo, @GivenName, @Surname, @Telephone, @Email, @Picture, @WrkGrp, @SectionID, @Gender)"
  62.  
  63.  
  64.  
  65.                     Dim myCommand As New OleDbCommand(SQLInsert, New OleDbConnection(connStr))
  66.  
  67.                                     myCommand.Connection.Open()
  68.  
  69.                                     Try
  70.  
  71.                                     With myCommand.Parameters
  72.  
  73.                                           myCommand.Parameters.Add("@EmployeeNo", OleDbType.VarChar).Value = txtEmployeeNo.Text
  74.                                   myCommand.Parameters.Add("@GivenName", OleDbType.VarChar).Value = txtGivenName.Text
  75.                                   myCommand.Parameters.Add("@Surname", OleDbType.VarChar).Value = txtSurname.Text
  76.                                           myCommand.Parameters.Add("@Telephone", OleDbType.VarChar).Value = txtTelephone.Text
  77.                                           myCommand.Parameters.Add("@Email", OleDbType.VarChar).Value = txtEmail.Text
  78.                                           myCommand.Parameters.Add("@Picture", OleDbType.Binary).Value = ImageContent
  79.                                           myCommand.Parameters.Add("@WrkGrp", OleDbType.VarChar).Value = txtWorkGroup.Text
  80.                                           myCommand.Parameters.Add("@SectionID", OleDbType.VarChar).Value = txtSection.Text
  81.  
  82.                                           Dim prmSex As String = ""
  83.  
  84.                                           If sexMale.Checked Then
  85.  
  86.                                                
  87.  
  88.                                                 prmSex = "M"
  89.  
  90.                                           Else
  91.  
  92.                                                 prmSex = "F"
  93.  
  94.                                           End If
  95.                                          
  96.                                           myCommand.Parameters.AddWithValue("@Gender", OleDbType.VarChar).Value = prmSex
  97.  
  98.                                      End With
  99.  
  100.  
  101.                            If CInt(myCommand.ExecuteNonQuery()) = 0 Then
  102.  
  103.                                       Response.Write("Insert Failed")
  104.  
  105.                            Else
  106.                                       Response.Write("New person successfully added!")
  107.                            End If
  108.  
  109.                                                 myCommand.Connection.Close()
  110.  
  111.                                                
  112.  
  113.                                     Catch ex As Exception
  114.  
  115.                                              Response.Write(ex.Message())  
  116.  
  117.                                     End Try
  118.  
  119.                         End Sub  
  120.  
  121.    
  122.  
  123.     </script>
  124.  
  125.    
  126.  
  127.   </HEAD>
  128.  
  129.   <body style="font: 10pt verdana">
  130.  
  131.  
  132.  
  133.     <form enctype="multipart/form-data" runat="server">
  134.  
  135.             <asp:Table Runat=server Width=50% BorderWidth=1 BackColor=Beige>
  136.  
  137.                         <asp:TableRow>
  138.  
  139.                                     <asp:TableCell ColumnSpan=2 BackColor="#ff0000">
  140.  
  141.                                     <asp:Label Font-Name="verdana" Font-size="12px" ForeColor="#ffffff" font-bold="True" Runat=server Text="Add New Person" />
  142.  
  143.                                     </asp:TableCell>
  144.  
  145.                         </asp:TableRow>
  146.  
  147.                         <asp:TableRow>
  148.  
  149.                                     <asp:TableCell HorizontalAlign="Right"><asp:Label Font-Name="verdana" Font-size="12px"  Runat=server Text="Employee No" /></asp:TableCell>
  150.  
  151.                                     <asp:TableCell><asp:TextBox id=txtEmployeeNo Runat=server /></asp:TableCell>
  152.  
  153.                         </asp:TableRow>
  154.  
  155.                         <asp:TableRow>
  156.  
  157.                                     <asp:TableCell HorizontalAlign="Right"><asp:Label Font-Name="verdana" Font-size="12px"  Runat=server Text="Given Name" /></asp:TableCell>
  158.  
  159.                                     <asp:TableCell><asp:TextBox id=txtGivenName Runat=server /></asp:TableCell>
  160.  
  161.                         </asp:TableRow>
  162.  
  163.                         <asp:TableRow>
  164.  
  165.                                     <asp:TableCell HorizontalAlign="Right"><asp:Label Font-Name="verdana" Font-size="12px"  Runat=server Text="Surname" /></asp:TableCell>
  166.  
  167.                                     <asp:TableCell><asp:TextBox id=txtSurname Runat=server /></asp:TableCell>
  168.  
  169.                         </asp:TableRow>
  170.  
  171.                         <asp:TableRow>
  172.  
  173.                                     <asp:TableCell HorizontalAlign="Right"><asp:Label Font-Name="verdana" Font-size="12px"  Runat=server Text="Telephone" /></asp:TableCell>
  174.  
  175.                                     <asp:TableCell><asp:TextBox id=txtTelephone Runat=server /></asp:TableCell>
  176.  
  177.                         </asp:TableRow>
  178.  
  179.                         <asp:TableRow>
  180.  
  181.                                     <asp:TableCell HorizontalAlign="Right"><asp:Label Font-Name="verdana" Font-size="12px"  Runat=server Text="Email" /></asp:TableCell>
  182.  
  183.                                     <asp:TableCell><asp:TextBox id="txtEmail" Runat=server /></asp:TableCell>
  184.  
  185.                         </asp:TableRow>
  186.  
  187.                         <asp:TableRow>
  188.  
  189.                                     <asp:TableCell HorizontalAlign="Right"><asp:Label Font-Name="verdana" Font-size="12px"  Runat=server Text="Image" /></asp:TableCell>
  190.  
  191.                                     <asp:TableCell><input type="file" id="PersonImage" runat=server /></asp:TableCell>
  192.  
  193.                         </asp:TableRow>
  194.  
  195.                         <asp:TableRow>
  196.  
  197.                                     <asp:TableCell HorizontalAlign="Right"><asp:Label Font-Name="verdana" Font-size="12px"  Runat=server Text="WorkGroup" /></asp:TableCell>
  198.  
  199.                                     <asp:TableCell><asp:TextBox id="txtWorkGroup" Runat=server /></asp:TableCell>
  200.  
  201.                         </asp:TableRow>
  202.  
  203.                         <asp:TableRow>
  204.  
  205.                                     <asp:TableCell HorizontalAlign="Right"><asp:Label Font-Name="verdana" Font-size="12px"  Runat=server Text="Section" /></asp:TableCell>
  206.  
  207.                                     <asp:TableCell><asp:TextBox id="txtSection" Runat=server /></asp:TableCell>
  208.  
  209.                         </asp:TableRow>
  210.  
  211.  
  212.                         <asp:TableRow>
  213.  
  214.                                     <asp:TableCell HorizontalAlign="Right"><asp:Label Font-Name="verdana" Font-size="12px"  Runat=server Text="Sex" /></asp:TableCell>
  215.  
  216.                                     <asp:TableCell>
  217.  
  218.                                                 <asp:RadioButton GroupName="sex" Font-Name="Verdana" Font-Size="12px" Text="Male" ID="sexMale" Runat=server />
  219.  
  220.                                                 <asp:RadioButton GroupName="sex" Font-Name="Verdana" Font-Size="12px" Text="FeMale" ID="sexFeMale" Runat=server />
  221.  
  222.                                     </asp:TableCell>
  223.  
  224.                         </asp:TableRow>
  225.                        
  226.  
  227.                         <asp:TableRow>
  228.  
  229.                                     <asp:TableCell ColumnSpan=2 HorizontalAlign=Center>
  230.  
  231.                                     <asp:Button Text="Add Person" OnClick="AddPerson" Runat=server />
  232.  
  233.                                     </asp:TableCell>
  234.  
  235.                         </asp:TableRow>
  236.  
  237.             </asp:Table>
  238.  
  239.     </form>
  240.  
  241.  
  242.  
  243.   </body>
  244.  
  245. </HTML>