How to Add DATE TYPE DATA using store procedure

  • I AM USING THIS CODE .
    create procedure SaveAirTicket
    (
    @DateOfBookAT date,
    @FromAT varchar(50),
    @ToAT varchar(50),
    @AirlineAT varchar(50),
    @PnrAT varchar(50),
    @DateOfTravelAT date,
    @PortalAT varchar(50),
    @PriceAT int
    )
    As
    insert into AirTicket (DateOfBooking,PlaceFrom,PlaceTo,AirLine,PnrNo,DateOfTravel,PortalName,Price) values( @DateOfBookAT,@FromAT,@ToAT,@AirlineAT,@PnrAT,@DateOfTravelAT,@PortalAT,
    @PriceAT)
    return

    BUT I AM GETTING THIS ERROR:-    An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll

    Additional information: Procedure or function 'SaveAirTicket' expects parameter '@DateOfBookAT', which was not supplied.

  • Can you post the values assigned to the input parameters when you called it? And the CREATE TABLE script for the table you're inserting into?

  • your code, i guess is a web page, script task or application, has to pass the parameters.
    here's an untested modification of some code i had to help get you started

    string thisConnString = "data source=MyServerName catalog=SandBox;Trusted_Connection=True;Application Name=AirlineTicketingSystem.exe;";
    System.Data.SqlClient.SqlParameter[] AllParams = new System.Data.SqlClient.SqlParameter[8];
    AllParams[0] = new System.Data.SqlClient.SqlParameter("@DateOfBookAT", SqlDbType.DateTime);
    AllParams[1] = new System.Data.SqlClient.SqlParameter("@FromAT", SqlDbType.VarChar, 50);
    AllParams[2] = new System.Data.SqlClient.SqlParameter("@ToAT", SqlDbType.VarChar, 50);
    AllParams[3] = new System.Data.SqlClient.SqlParameter("@AirlineAT", SqlDbType.VarChar, 50);
    AllParams[4] = new System.Data.SqlClient.SqlParameter("@PnrAT", SqlDbType.VarChar, 50);
    AllParams[5] = new System.Data.SqlClient.SqlParameter("@DateOfTravelAT", SqlDbType.DateTime);
    AllParams[6] = new System.Data.SqlClient.SqlParameter("@PortalAT", SqlDbType.VarChar, 50);
    AllParams[7] = new System.Data.SqlClient.SqlParameter("@PriceAT", SqlDbType.Int);

    AllParams[0].Value = DateTime.Today;
    AllParams[1].Value = "FLL";
    AllParams[2].Value = "LAX"
    AllParams[3].Value = "AMERICAN"
    AllParams[4].Value = "";
    AllParams[5].Value = DateTime.Today;
    AllParams[6].Value = "Expedia"
    AllParams[7].Value = 450;
    --my sqlhelper class form microsoft application blocks has the Connection and Command object
    SQLHelper.SqlHelper.ExecuteNonQuery(thisConnString, CommandType.StoredProcedure, "SandBox.dbo.SaveAirTicket", AllParams);

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply