Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I want to use stored procedure. I written procedure its execute successfully.
but i didn't get how to pass the value in .cs file.

My code is as follows:-
SQL
SqlConnection con = dt.SqlCon;
       dt.OpenCon();
       cmd.CommandType = CommandType.StoredProcedure;
       cmd.CommandText = "sp_master_applicant";

       cmd.parameters.addwithvalue("@company_name", drdwncompany.selectedvalue.tostring());
       cmd.parameters.addwithvalue("@email_address", txtemail_id.text);
       cmd.parameters.addwithvalue("@first_name", txtfirstname.text);
       cmd.parameters.addwithvalue("@last_name", txtlast_name.text);
       cmd.parameters.addwithvalue("@password", txtpassword.text);
       cmd.parameters.addwithvalue("@confirm_password", txtre_password.text);
       cmd.parameters.addwithvalue("@phone_no", txt_phnno.text);
       cmd.parameters.addwithvalue("@mobile_no", txtmobile.text);
       cmd.parameters.addwithvalue("@roles", drdwrole.selectedvalue.tostring());
       cmd.parameters.addwithvalue("@li_admin", ckadmin.checked ? "1" : "0");
       cmd.parameters.addwithvalue("@li_application_form", ckemployee_registration.checked ? "1" : "0");
Posted
Updated 25-Nov-14 19:21pm
v2

 
Share this answer
 
C#
using (SqlConnection con = new SqlConnection(dt.SqlCon)) {
    using (SqlCommand cmd = new SqlCommand("sp_master_applicant")) {
      cmd.CommandType = CommandType.StoredProcedure;

      cmd.parameters.addwithvalue("@company_name",drdwncompany.selectedvalue.tostring());
        cmd.parameters.addwithvalue("@email_address", txtemail_id.text);
        cmd.parameters.addwithvalue("@first_name", txtfirstname.text);
        cmd.parameters.addwithvalue("@last_name", txtlast_name.text);
        cmd.parameters.addwithvalue("@password", txtpassword.text);
        cmd.parameters.addwithvalue("@confirm_password", txtre_password.text);
        cmd.parameters.addwithvalue("@phone_no", txt_phnno.text);
        cmd.parameters.addwithvalue("@mobile_no", txtmobile.text);
        cmd.parameters.addwithvalue("@roles", drdwrole.selectedvalue.tostring());
        cmd.parameters.addwithvalue("@li_admin", ckadmin.checked ? "1" : "0");
        cmd.parameters.addwithvalue("@li_application_form", ckemployee_registration.checked ? "1" : "0");

      con.Open();
      cmd.ExecuteNonQuery();
    }
  }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900