- No records return when the value being pass in parameter is from Function
- class NewString
- {
- public static string RemoveExtraSpaces(string xString)
- {
- string iTemp = string.Empty;
- xString = xString.Trim();
- string[] words = xString.Split(' ');
- foreach (string xWor in words)
- {
- string xxWor = xWor.Trim();
- if (xxWor.Length > 0)
- {
- iTemp += " " + xxWor;
- }
- }
- return iTemp;
- }
- }
- NewString.RemoveExtraSpaces(" Stack OverFlow ")
- ==> will return "Stack OverFlow"
- private void LoadCandidateList(bool SearchAll, string iKey)
- {
- using (MySqlConnection xConn = new MySqlConnection(ConnectionClass.ConnectionString))
- {
- using (MySqlCommand xCOmm = new MySqlCommand())
- {
- xCOmm.Connection = xConn;
- xCOmm.CommandType = CommandType.StoredProcedure;
- xCOmm.CommandText = "LoadCandidateList";
- xCOmm.Parameters.AddWithValue("LoadAll", Convert.ToInt16(SearchAll));
- string fnlKey = iKey.Trim();
- // when i use the code above, the procedure performs normally
- // but if i use the code below, no records will be return
- // why is that? i prompt it in the MessageBox to check
- // and displays the correct value.
- // string fnlKey = NewString.RemoveExtraSpaces(iKey.Trim());
- // MessageBox.Show(fnlKey); // => return correct value
- xCOmm.Parameters.AddWithValue("iKey", fnlKey);
- xCOmm.Parameters.AddWithValue("iCurrentID", _CurrentEventID);
- using (DataSet ds = new DataSet())
- {
- using (MySqlDataAdapter xAdapter = new MySqlDataAdapter(xCOmm))
- {
- try
- {
- xConn.Open();
- xAdapter.Fill(ds,"CandidateList");
- grdResult.DataSource = ds.Tables["CandidateList"];
- }
- catch (MySqlException ex)
- {
- MessageBox.Show(ex.Message.ToString(), "Function Error <LoadCandidateList>", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- }
- finally
- {
- xConn.Close();
- }
- }
- }
- }
- }
- }
- string.Join(" ", xString.Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries);
- static class StringExtensions {
- public static string RemoveExtraSpaces(this string xString) {
- return string.Join(" ", xString.Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries));
- }
- }
- <asp:TextBox ID="Name" runat="server" Text='RemoveExtraSpaces(<%# Bind("Name") %>);' AutoPostBack="false"></asp:TextBox>