Guest User

Untitled

a guest
May 2nd, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. No records return when the value being pass in parameter is from Function
  2. class NewString
  3. {
  4. public static string RemoveExtraSpaces(string xString)
  5. {
  6. string iTemp = string.Empty;
  7. xString = xString.Trim();
  8. string[] words = xString.Split(' ');
  9. foreach (string xWor in words)
  10. {
  11. string xxWor = xWor.Trim();
  12. if (xxWor.Length > 0)
  13. {
  14. iTemp += " " + xxWor;
  15. }
  16.  
  17. }
  18. return iTemp;
  19. }
  20. }
  21.  
  22. NewString.RemoveExtraSpaces(" Stack OverFlow ")
  23. ==> will return "Stack OverFlow"
  24.  
  25. private void LoadCandidateList(bool SearchAll, string iKey)
  26. {
  27. using (MySqlConnection xConn = new MySqlConnection(ConnectionClass.ConnectionString))
  28. {
  29. using (MySqlCommand xCOmm = new MySqlCommand())
  30. {
  31. xCOmm.Connection = xConn;
  32. xCOmm.CommandType = CommandType.StoredProcedure;
  33. xCOmm.CommandText = "LoadCandidateList";
  34. xCOmm.Parameters.AddWithValue("LoadAll", Convert.ToInt16(SearchAll));
  35.  
  36. string fnlKey = iKey.Trim();
  37. // when i use the code above, the procedure performs normally
  38. // but if i use the code below, no records will be return
  39. // why is that? i prompt it in the MessageBox to check
  40. // and displays the correct value.
  41.  
  42. // string fnlKey = NewString.RemoveExtraSpaces(iKey.Trim());
  43. // MessageBox.Show(fnlKey); // => return correct value
  44.  
  45. xCOmm.Parameters.AddWithValue("iKey", fnlKey);
  46. xCOmm.Parameters.AddWithValue("iCurrentID", _CurrentEventID);
  47.  
  48. using (DataSet ds = new DataSet())
  49. {
  50. using (MySqlDataAdapter xAdapter = new MySqlDataAdapter(xCOmm))
  51. {
  52. try
  53. {
  54. xConn.Open();
  55. xAdapter.Fill(ds,"CandidateList");
  56. grdResult.DataSource = ds.Tables["CandidateList"];
  57. }
  58. catch (MySqlException ex)
  59. {
  60. MessageBox.Show(ex.Message.ToString(), "Function Error <LoadCandidateList>", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  61. }
  62. finally
  63. {
  64. xConn.Close();
  65. }
  66. }
  67. }
  68. }
  69. }
  70. }
  71.  
  72. string.Join(" ", xString.Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries);
  73.  
  74. static class StringExtensions {
  75. public static string RemoveExtraSpaces(this string xString) {
  76. return string.Join(" ", xString.Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries));
  77. }
  78. }
  79.  
  80. <asp:TextBox ID="Name" runat="server" Text='RemoveExtraSpaces(<%# Bind("Name") %>);' AutoPostBack="false"></asp:TextBox>
Advertisement
Add Comment
Please, Sign In to add comment