Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. public string AddCampus(Campus objCampus)
  2. {
  3. //string Params = "@Activity,@Name,@PhoneNo,@Email,@Logo,@StatusId,@CountryId,@CityId,@StateId,@DistrictId,@ClientId,@Pincode,@AddressLine1,@AddressLine2,@Area,@Street";
  4. //string Values = "Add" + ',' + objCampus.Name + ',' + objCampus.PhoneNo + ',' + objCampus.Email + ',' + objCampus.Logo + "," + objCampus.StatusId + ","+objCampus.CampusAddress.CountryId + "," + objCampus.CampusAddress.CityId + "," + objCampus.CampusAddress.StateId + "," + objCampus.CampusAddress.DistrictId + "," + objCampus.ClientId + "," + objCampus.CampusAddress.Pincode + "," + objCampus.CampusAddress.AddressLine1 + "," + objCampus.CampusAddress.AddressLine2 + "," + objCampus.CampusAddress.Area + "," + objCampus.CampusAddress.Streat;
  5. //return Connection.CommandExecuteNonQuery(Params, Values,true, "sprCampus");
  6. }
  7.  
  8. I made this and it works but i have just coommented that.This was the implementation
  9.  
  10.  
  11. public static string CommandExecuteNonQuery(string Parameters,string Values,bool IsStoredProcedure,string command)
  12. { string[] Parameter = Parameters.Split(',');
  13. string[] Value = Values.Split(',');
  14. string s_Message = "";
  15. if (Parameter.Count() < Value.Count())
  16. {
  17. s_Message = "Number of Paramters Supplied is less than Number of Values Supplied.";
  18. return s_Message;
  19. }
  20. else if (Parameter.Count() > Value.Count())
  21. {
  22. s_Message = "Number of Values Supplied is less than Number of Parameters Supplied.";
  23. return s_Message;
  24. }
  25. else
  26. {
  27. SqlCommand cmd = new SqlCommand();
  28. for (var i = 0; i < Parameter.Count(); i++)
  29. {
  30. cmd.Parameters.AddWithValue(Parameter[i], Value[i]);
  31.  
  32. }
  33. cmd.CommandText = command;
  34. if (IsStoredProcedure)
  35. cmd.CommandType = CommandType.StoredProcedure;
  36. string saveSuccess = string.Empty;
  37. int execute = 0;
  38. using (SqlConnection con = new SqlConnection(sqlConStr))
  39. {
  40. try
  41. {
  42. con.Open();
  43. cmd.Connection = con;
  44. execute = cmd.ExecuteNonQuery();
  45. if (execute > 0)
  46. {
  47. s_Message = "Record Saved";
  48. }
  49. else
  50. s_Message = "Operation Failed";
  51.  
  52.  
  53.  
  54. }
  55. catch (Exception excp)
  56. {
  57. s_Message = excp.Message;
  58. }
  59.  
  60. }
  61. }
  62. return s_Message.ToString();
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement