Inserting Datas To BackEnd : Passing Parameters to SP using c#

private void Button1_Click(object sender, System.EventArgs e)


{


string strCon = "database=CareSourceOhio; server=.; user id=sa; pwd=;";


string strSql = "SP_AddUserDetails";


SqlConnection objCon =new SqlConnection(strCon);


objCon.Open();


SqlCommand objCmd = new SqlCommand();


objCmd.Connection = objCon;


objCmd.CommandText = strSql;


objCmd.CommandType = CommandType.StoredProcedure;


SqlParameter objUserID = new SqlParameter("@UserID",DbType.String);


SqlParameter objFirstName = new SqlParameter("@FirstName",DbType.String);


SqlParameter objLastName = new SqlParameter("@LastName",DbType.String);


SqlParameter objTaxID = new SqlParameter("@TaxID",DbType.String);


SqlParameter objAffiliationID = new SqlParameter("@AffliationID",
DbType.String);


SqlParameter objAttentionTo = new SqlParameter("@AttentionTo",DbType.String
);


objCmd.Parameters.Add (objUserID);


objCmd.Parameters.Add (objFirstName);


objCmd.Parameters.Add (objLastName);


objCmd.Parameters.Add (objTaxID);


objCmd.Parameters.Add (objAffiliationID);


objCmd.Parameters.Add (objAttentionTo);


objUserID.Value = "Ring";


objFirstName.Value = "Ring";


objLastName.Value = "Ring";


objTaxID.Value = "Ring";


objAffiliationID.Value = "Ring";


objAttentionTo.Value = "Ring";


objCmd.ExecuteNonQuery();

}

No comments: