SHOWING ERROR- EXCEPT A PARAMETER WHICH IS NOT SUPPLIED

Pravesh Singh

Total Post:101

Points:709
Posted by  Pravesh Singh
 1220  View(s)
Ratings:
Rate this:

I want to execute the query but on the datastore parameter it is showing an error excepts a parameter which is not supplied.Please help me out regarding this.

 

My code is-

 

                           SqlConnection conn = new SqlConnection(str);

                           conn.Open();

                           Console.WriteLine("TicketNo {0}", itm);

 

                           string SwimSR = "";

                           SwimSR += "Insert into SwimSR1(Id,State,Title,Datastore,AreaId,AreaPath,PlannedStartDate,PlannedEndDate,RequestedEta,SeManTexEta,Owner,Reason,ChangedBy,ChangedDate,CreatedBy,CreatedDate,NodeName,Trio,Type,BusinessCategory,Description)";

                           SwimSR += "Values(@Id,@State,@Title,@Datastore,@AreaId,@AreaPath,@PlannedStartDate,@PlannedEndDate,@RequestedEta,@SeManTexEta,@Owner,@Reason,@ChangedBy,@ChangedDate,@CreatedBy,@CreatedDate,@NodeName,@Trio,@Type,@BusinessCategory,@Description)";

                             SqlCommand cmd = new SqlCommand(SwimSR, conn);

 

                             cmd.Parameters.Add(new SqlParameter("@Id",swimTicket[itm].swimTicketData.Id));

 

                             cmd.Parameters.Add(new SqlParameter("@State",swimTicket[itm].swimTicketData.State));

                             cmd.Parameters.Add(new SqlParameter("@Title",swimTicket[itm].swimTicketData.Title));

                             cmd.Parameters.Add(new SqlParameter("@Datastore",swimTicket[itm].swimTicketData.Datastore));

                             cmd.Parameters.Add(new SqlParameter("@AreaId", swimTicket[itm].swimTicketData.AreaId));

                             cmd.Parameters.Add(new SqlParameter("@AreaPath", swimTicket[itm].swimTicketData.AreaPath));

                             cmd.Parameters.Add(new SqlParameter("@PlannedStartDate", swimTicket[itm].swimTicketData.PlannedStartDate));

                             cmd.Parameters.Add(new SqlParameter("@PlannedEnddate", swimTicket[itm].swimTicketData.PlannedEndDate));

                             cmd.Parameters.Add(new SqlParameter("@RequestedEta", swimTicket[itm].swimTicketData.RequestedEta));

                             cmd.Parameters.Add(new SqlParameter("@SemanTexEta", swimTicket[itm].swimTicketData.SeManTexEta));

                             cmd.Parameters.Add(new SqlParameter("@Owner", swimTicket[itm].swimTicketData.Owner));

                             cmd.Parameters.Add(new SqlParameter("@Reason", swimTicket[itm].swimTicketData.Reason));

                             cmd.Parameters.Add(new SqlParameter("@ChangedBy", swimTicket[itm].swimTicketData.ChangedBy));

                             cmd.Parameters.Add(new SqlParameter("@ChangedDate", swimTicket[itm].swimTicketData.ChangedDate));

                             cmd.Parameters.Add(new SqlParameter("@CreatedBy", swimTicket[itm].swimTicketData.CreatedBy));

                             cmd.Parameters.Add(new SqlParameter("@CreatedDate", swimTicket[itm].swimTicketData.CreatedDate));

                             cmd.Parameters.Add(new SqlParameter("@NodeName", swimTicket[itm].swimTicketData.NodeName));

                             cmd.Parameters.Add(new SqlParameter("@Trio", swimTicket[itm].swimTicketData.Trio));

                             cmd.Parameters.Add(new SqlParameter("@Type", swimTicket[itm].swimTicketData.Type));

                             cmd.Parameters.Add(new SqlParameter("@BusinessCategory", swimTicket[itm].swimTicketData.BusinessCategory));

                             cmd.Parameters.Add(new SqlParameter("@Description", swimTicket[itm].swimTicketData.Description));

 

 

                           cmd.ExecuteNonQuery();

                           Console.WriteLine("added");

                           conn.Close();

  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: Showing Error- Except a parameter which is not supplied

    You used @SeManTexEta in your sql command but you declared in your parameter part as a @SemanTexEta.

    As you can see, these are different.

    Change your

    cmd.Parameters.Add(new SqlParameter("@SemanTexEta", swimTicket[itm].swimTicketData.SeManTexEta));

    to

    cmd.Parameters.Add(new SqlParameter("@SeManTexEta", swimTicket[itm].swimTicketData.SeManTexEta));

    Also SqlParameterCollection.Add method has been deprecated. You can use SqlParameterCollection.AddWithValue method instead. Like;

    cmd.Parameters.AddWithValue("@SeManTexEta", swimTicket[itm].swimTicketData.SeManTexEta);

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!