hi all

store procedure

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[insertguestinfo]

@Guest_ID int,
@first_name nvarchar(50),
@Last_name nvarchar(50),
@Gender_ID int,
@Martial_ID int,
@Phone_number  int,
@email_address nvarchar(50)
as
begin
insert into GuestInfo(Guest_ID,First_name,Last_name,Gender_ID,Martial_ID,Phone_number,Email_address) 
values(@Guest_ID,@first_name,@Last_name,@Gender_id,@Martial_id,@Phone_number,@email_address)


END






 public void add()
        {




                Guest_info gst_info=new Guest_info();

                string ConString = @"Data Source=USER-PC\SQLEXPRESS;Initial Catalog=htm;Integrated Security=True";
                SqlConnection con = new SqlConnection(ConString);
                //string query = "Insert into GuestInfo(first name,last name,gender,martial status,phone number,email_address) values (" + Guest_id + ",'" + First_name+ "','" + Last_name + "','" + Gender_status + "','" + Martial_status + "','" + Phone_numb + "','" + Email_address + "')";
                //SqlCommand cmd = new SqlCommand(query, con);
                con.Open();
                SqlCommand com = new SqlCommand("insertguestinfo", con);


                com.CommandType = CommandType.StoredProcedure;
                com.Parameters.Add(new SqlParameter("@guest_ID",gst_info.Guest_id));
                com.Parameters.Add(new SqlParameter("@first_name", gst_info.First_name));
                com.Parameters.Add(new SqlParameter("@Last_name", gst_info.Last_name));
                com.Parameters.Add(new SqlParameter("@Gender_ID", gst_info.Gender_status));
                com.Parameters.Add(new SqlParameter("@Martial_ID",gst_info.Martial_status));
                com.Parameters.Add(new SqlParameter("@phone_number",gst_info.Phone_numb ));
                com.Parameters.Add(new SqlParameter("@email_address",gst_info.Email_address ));
                com.ExecuteNonQuery();
                con.Close();

            }

when i run the code the following error is occured

Procedure or function 'insertguestinfo' expects parameter '@first_name', which was not supplied.
where is th probelm :@

Edited 4 Years Ago by diya45

I think Line Numer 38 as con.open() and Line number 42
com.CommandType = CommandType.StoredProcedure;
should be after Parameters it should after line no 40 as below

SqlCommand("insertguestinfo", con);

com.Parameters.Add(new SqlParameter("@guest_ID",gst_info.Guest_id));
com.Parameters.Add(new SqlParameter("@first_name", gst_info.First_name));
com.Parameters.Add(new SqlParameter("@Last_name", gst_info.Last_name));
com.Parameters.Add(new SqlParameter("@Gender_ID", gst_info.Gender_status));
com.Parameters.Add(new SqlParameter("@Martial_ID",gst_info.Martial_status));                    com.Parameters.Add(new SqlParameter("@phone_number",gst_info.Phone_numb ));
com.Parameters.Add(new SqlParameter("@email_address",gst_info.Email_address ));
     con.Open();
     com.CommandType = CommandType.StoredProcedure;
     com.ExecuteNonQuery();
                con.Close();

Hope This Help You.....................

This article has been dead for over six months. Start a new discussion instead.