locked
Parameterized Query RRS feed

  • Question

  • Hey Folks,

    Can Someone tell me why I am getting this message.  Not Sure what this means.

    Many Thanks!!!

    Parameterized Query '(@WorkSheetID nvarchar(14),@Origin nvarchar(5),@DealerName nvarc' expects parameter @Address, which was not supplied.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.SqlClient.SqlException: Parameterized Query '(@WorkSheetID nvarchar(14),@Origin nvarchar(5),@DealerName nvarc' expects parameter @Address, which was not supplied.

    Source Error:

    Line 401:                    .Add(New SqlParameter("@DOB", sDOB))
    Line 402:                End With
    Line 403:                ra = myCommand.ExecuteNonQuery()
    Line 404:                myConnection.Close()
    Line 405:                'Lets Check to see if there is a Co Applicant

    Here is my Code:

    Dim ra AsInteger
    Dim myConnection As SqlConnection
    Dim myCommand As SqlCommand
    Dim connString AsString =
    "Server=.\SQLEXPRESS;AttachDbFilename=|DataDirecto ry|CustomerInfo.mdf;Integrated Security=True;User Instance=True"
    Dim CPhoneNum, CWorkNum, CCellNum, sWorkSheetNum, sSaleOrigin As
    String
    Dim sDealerShipName, sBkupSlsRep, sDateCreated, sFirstName, sMiddleName, slastname, sBuyAddress, sSSN, sDOB As
    String
    Dim scity, sState, sZip, sEmailAddres, sBuyersCounty, sSalesTax As
    String
    Dim SlsManLoginN As
    String
    Dim myPrincipal As IPrincipal = Me.User
    'Customer Information
    sWorkSheetNum = lblCustWksnum.Text
    sSaleOrigin = lblSaleOrigin.Text
    sDealerShipName = lblDealerShipName.Text
    sDateCreated = lblDateCreated.Text
    sBkupSlsRep = lblBkupSlsRep.Text
    sFirstName = lblcFirstName.Text
    sMiddleName = lblcMiddleName.Text
    slastname = lblcLastName.Text
    sBuyAddress = rBuyAddress
    scity = rcity
    sState = rState
    sZip = rZip
    sEmailAddres = lblEmailAddres.Text
    sBuyersCounty = lblBuyersCounty.Text
    sSalesTax = lblSalesTax.Text
    sSSN = lblSSN.Text
    sDOB = lblDOB.Text
    'Lets get the Current Logged on User
    SlsManLoginN = lblSlsRep.Text
    myConnection = New SqlConnection
    myConnection.ConnectionString = connString
    myConnection.Open()
    CPhoneNum = lblHnum.Text
    CWorkNum = lblWnum.Text
    CCellNum = lblCnum.Text
    Const sql AsString = "Insert into CustomerTable (WorkSheetID, Origin, DealerName, DateCreated, SalesRep, " _
    + "BkupSalesRep, FirstName, MiddleName, LastName, Address, City, State, Zip, HomePhone, WorkPhone, " _
    + "CellPhone, Email, County, SalesTax, SS#, DOB) Values (@WorkSheetID, @Origin, @DealerName, @DateCreated, " _
    +
    "@SalesRep, @BkupSalesRep, @FirstName, @MiddleName, @LastName, @Address, @City, @State, @Zip, @HomePhone, @WorkPhone, @CellPhone, @Email, @County, @SalesTax, @SS#, @DOB)"
    myCommand = New SqlCommand(sql, myConnection)
    With myCommand.Parameters
    .Add(New SqlParameter("@WorkSheetID", sWorkSheetNum))
    .Add(New SqlParameter("@Origin", sSaleOrigin))
    .Add(New SqlParameter("@DealerName", sDealerShipName))
    .Add(New SqlParameter("@DateCreated", sDateCreated))
    .Add(New SqlParameter("@SalesRep", SlsManLoginN))
    .Add(New SqlParameter("@BkupSalesRep", sBkupSlsRep))
    .Add(New SqlParameter("@FirstName", sFirstName))
    .Add(New SqlParameter("@MiddleName", sMiddleName))
    .Add(New SqlParameter("@LastName", slastname))
    .Add(New SqlParameter("@Address", sBuyAddress))
    .Add(New SqlParameter("@City", scity))
    .Add(New SqlParameter("@State", sState))
    .Add(New SqlParameter("@Zip", sZip))
    .Add(New SqlParameter("@HomePhone", CPhoneNum))
    .Add(New SqlParameter("@WorkPhone", CWorkNum))
    .Add(New SqlParameter("@CellPhone", CCellNum))
    .Add(New SqlParameter("@Email", sEmailAddres))
    .Add(New SqlParameter("@County", sBuyersCounty))
    .Add(New SqlParameter("@SalesTax", sSalesTax))
    .Add(New SqlParameter("@SS#", sSSN))
    .Add(New SqlParameter("@DOB", sDOB))
    End
    With
    ra = myCommand.ExecuteNonQuery()
    myConnection.Close()


     

    Thursday, May 4, 2006 2:34 AM

Answers

  • Is sBuyAddress a null by any chance? If so, try passing DBNull.Value instead.
    Thursday, May 4, 2006 11:39 AM
  • Sometimes you could get this error in a case if one of the field names is a reserved word. If you still experience this issue, try to wrap each field name in your SQL statement into square brackets, like

    Const sql AsString = "Insert into CustomerTable ([WorkSheetID], [Origin], [DealerName] .....,

    Friday, May 5, 2006 10:20 AM

All replies

  • Is sBuyAddress a null by any chance? If so, try passing DBNull.Value instead.
    Thursday, May 4, 2006 11:39 AM
  • Sometimes you could get this error in a case if one of the field names is a reserved word. If you still experience this issue, try to wrap each field name in your SQL statement into square brackets, like

    Const sql AsString = "Insert into CustomerTable ([WorkSheetID], [Origin], [DealerName] .....,

    Friday, May 5, 2006 10:20 AM