How to use the procedure I write it in last post in your asp.net web application

In my last post I just create a store procedure to insert data into 2 tables, here is the c# code how do you use it in your project.

I write a event so for anyone need it just change you connection string then will be reuse.


protected void ButtonClick_StoreRecords(string parameterRef, string parameterLM_Booking_Ref,  string parameterLMStatus, DateTime parameterEntry_datetime)
    {
        string CS = ConfigurationManager.ConnectionStrings["youconnectionstringhere"].ConnectionString;
        using (SqlConnection con = new SqlConnection(CS))
        {
            SqlCommand cmd = new SqlCommand("spStoreLMStatusRecording", con);
            cmd.CommandType = CommandType.StoredProcedure;

            SqlParameter paramRef = new SqlParameter();
            paramRef.ParameterName = "@parameterRef";
            paramRef.Value = parameterRef;
            cmd.Parameters.Add(paramRef);

            SqlParameter paramLM_Booking_Ref = new SqlParameter();
            paramLM_Booking_Ref.ParameterName = "@parameterLM_Booking_Ref";
            paramLM_Booking_Ref.Value = parameterLM_Booking_Ref;
            cmd.Parameters.Add(paramLM_Booking_Ref);
         

            SqlParameter paramLMStatus = new SqlParameter();
            paramLMStatus.ParameterName = "@parameterLMStatus";
            paramLMStatus.Value = parameterLMStatus;
            cmd.Parameters.Add(paramLMStatus);


            SqlParameter paramEntry_datetime = new SqlParameter();
            paramEntry_datetime.ParameterName = "@parameterEntry_datetime";
            paramEntry_datetime.Value = parameterEntry_datetime;
            cmd.Parameters.Add(paramEntry_datetime);

            con.Open();
            cmd.ExecuteNonQuery();

        }
     
    }


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s