.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Windows Application >> Post New QuestionBookmark and Share Subscribe to Forum

Remove Space

Posted By: kamlesh     Posted Date: February 04, 2011    Points:2   Category :Windows Application
hi.
i have created one Query for Searching the Address

SearchQuery = SearchQuery + " and (Address like '%" + txtContactSearch.Text.Trim() + "%')";

when i am storing address in one line means PuneMaharashtra then It search Perfect.

but if i store the address like (Pune Enter Here(Means On Next Line) Maharashtra) so it is not searching so please help me

Thanks
Kamlesh

Responses
Author: Blessy Baby             
Posted Date: February 04, 2011     Points: 5   

Hi

Try like below, replace all spce in the field

SearchQuery = SearchQuery + " and (repalce(Address,' ','') like '%" + txtContactSearch.Text.Trim() + "%')";



Blessy Baby
Project Lead
Digitalmesh Softech India (p) Limited
Cochin,Kerala
Author: kamlesh             
Posted Date: February 04, 2011     Points: 5   

Thanks But still it is not working

I have write the address on two lines
like

Address:
Cochin (Here I Enter Button Press)
Kerala


But it store in database like CochinKerala....And While searching CochinKerala is it not Searching
if i search Cochin then it search..but for CochinKerala not working

Thanks And Regards.
Kamlesh Nikam
Author: shankey             
Posted Date: February 04, 2011     Points: 5   

hi,

I tried as below and it give the result:

insert into address values('PuneMaharashtra')
insert into address values('Pune' + CHAR(13) + 'Maharashtra')
select * from address where addresscol like '%Maharashtra%'
select * from address where addresscol like '%Pune%'

Are you looking for something like this.....

Please reply

Shankey
Author: kamlesh             
Posted Date: March 14, 2011     Points: 20   

public static List<MailDetailDTO> GetMailDetailByCondition(string StrQuery)
{
SqlConnection Conn;
List<MailDetailDTO> MailList = new List<MailDetailDTO>();
try
{

Conn = new SqlConnection(Common.ConnectionString);
Conn.Open();
SqlCommand sqlCmd = new SqlCommand(StrQuery, Conn);
sqlCmd.CommandType = CommandType.Text;


SqlDataAdapter da = new SqlDataAdapter(sqlCmd);
DataTable dt = new DataTable();
da.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++)
{
MailDetailDTO MailDetail = new MailDetailDTO();
MailDetail.ID = Convert.ToInt32(dt.Rows[i]["ID"]);
MailDetail.RouteFolderId = Convert.ToInt32(dt.Rows[i]["RouteFolderId"]);
MailDetail.SubFolderId = Convert.ToInt32(dt.Rows[i]["SubFolderId"]);
MailDetail.MailFrom = Convert.ToString(dt.Rows[i]["MailFrom"]);
MailDetail.MailTo = Convert.ToString(dt.Rows[i]["MailTo"]);
MailDetail.MailCc = Convert.ToString(dt.Rows[i]["MailCc"]);
MailDetail.MailBcc = Convert.ToString(dt.Rows[i]["MailBcc"]);
MailDetail.MailSubject = Convert.ToString(dt.Rows[i]["MailSubject"]);
MailDetail.MailBody = Convert.ToString(dt.Rows[i]["MailBody"]);
MailDetail.MailDate = Convert.ToDateTime(dt.Rows[i]["MailDate"]);
MailDetail.MailSize = Convert.ToInt32(dt.Rows[i]["MailSize"]);
MailDetail.HasAttechment = Convert.ToBoolean(dt.Rows[i]["HasAttechment"]);
MailDetail.MailBodyNew = Convert.ToString(dt.Rows[i]["MailBodyPlain"]);

MailList.Add(MailDetail);
}
Conn.Close();
sqlCmd.Dispose();
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
clsError.LogError(ex);
}

return MailList;

}




public static List<MailDetailDTO> GetMailDetailByRouteNode(int RoutFolderId, string Filter)
{
SqlConnection Conn;
List<MailDetailDTO> MailList = new List<MailDetailDTO>();
try
{

Conn = new SqlConnection(Common.ConnectionString);
Conn.Open();
SqlCommand sqlCmd = new SqlCommand("GetMailDetailByRouteFolderID", Conn);
sqlCmd.CommandType = CommandType.StoredProcedure;

sqlCmd.Parameters.Add(new SqlParameter("@RouteFolderId", SqlDbType.Int));
sqlCmd.Parameters["@RouteFolderId"].Value = RoutFolderId;

sqlCmd.Parameters.Add(new SqlParameter("@Filter", SqlDbType.VarChar));
sqlCmd.Parameters["@Filter"].Value = Filter;

SqlDataAdapter da = new SqlDataAdapter(sqlCmd);
DataTable dt = new DataTable();
da.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++)
{
MailDetailDTO MailDetail = new MailDetailDTO();
MailDetail.ID = Convert.ToInt32(dt.Rows[i]["ID"]);
MailDetail.RouteFolderId = Convert.ToInt32(dt.Rows[i]["RouteFolderId"]);
MailDetail.SubFolderId = Convert.ToInt32(dt.Rows[i]["SubFolderId"]);
MailDetail.MailFrom = Convert.ToString(dt.Rows[i]["MailFrom"]);
MailDetail.MailTo = Convert.ToString(dt.Rows[i]["MailTo"]);
MailDetail.MailCc = Convert.ToString(dt.Rows[i]["MailCc"]);
MailDetail.MailBcc = Convert.ToString(dt.Rows[i]["MailBcc"]);
MailDetail.MailSubject = Convert.ToString(dt.Rows[i]["MailSubject"]);
MailDetail.MailBody = Convert.ToString(dt.Rows[i]["MailBody"]);
MailDetail.MailDate = Convert.ToDateTime(dt.Rows[i]["MailDate"]);
MailDetail.MailSize = Convert.ToInt32(dt.Rows[i]["MailSize"]);
MailDetail.HasAttechment = Convert.ToBoolean(dt.Rows[i]["HasAttechment"]);
MailDetail.MailBodyNew = Convert.ToString(dt.Rows[i]["MailBodyPlain"]);

MailList.Add(MailDetail);

}
Conn.Close();
sqlCmd.Dispose();
}
catch (Exception ex)
{
// throw new Exception(ex.Message);
// MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
clsError.LogError(ex);
}

return MailList;

}



public static List<MailDetailDTO> GetMailDetailBySubNode(int SubFolderId, string Filter)
{
SqlConnection Conn;
List<MailDetailDTO> MailList = new List<MailDetailDTO>();
try
{

Conn = new SqlConnection(Common.ConnectionString);
Conn.Open();
SqlCommand sqlCmd = new SqlCommand("GetMailDetailBysubFolderID", Conn);
sqlCmd.CommandType = CommandType.StoredProcedure;

sqlCmd.Parameters.Add(new SqlParameter("@SubFolderId", SqlDbType.Int));
sqlCmd.Parameters["@SubFolderId"].Value = SubFolderId;

sqlCmd.Parameters.Add(new SqlParameter("@Filter", SqlDbType.VarChar));
sqlCmd.Parameters["@Filter"].Value = Filter;

SqlDataAdapter da = new SqlDataAdapter(sqlCmd);
DataTable dt = new DataTable();
da.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++)
{
MailDetailDTO MailDetail = new MailDetailDTO();
MailDetail.ID = Convert.ToInt32(dt.Rows[i]["ID"]);
MailDetail.RouteFolderId = Convert.ToInt32(dt.Rows[i]["RouteFolderId"]);
MailDetail.SubFolderId = Convert.ToInt32(dt.Rows[i]["SubFolderId"]);
MailDetail.MailFrom = Convert.ToString(dt.Rows[i]["MailFrom"]);
MailDetail.MailTo = Convert.ToString(dt.Rows[i]["MailTo"]);
MailDetail.MailCc = Convert.ToString(dt.Rows[i]["MailCc"]);
MailDetail.MailBcc = Convert.ToString(dt.Rows[i]["MailBcc"]);
MailDetail.MailSubject = Convert.ToString(dt.Rows[i]["MailSubject"]);
MailDetail.MailBody = Convert.ToString(dt.Rows[i]["MailBody"]);
MailDetail.MailDate = Convert.ToDateTime(dt.Rows[i]["MailDate"]);
MailDetail.MailSize = Convert.ToInt32(dt.Rows[i]["MailSize"]);
MailDetail.HasAttechment = Convert.ToBoolean(dt.Rows[i]["HasAttechment"]);
MailDetail.MailBodyNew = Convert.ToString(dt.Rows[i]["MailBodyPlain"]);
MailList.Add(MailDetail);

}
Conn.Close();
sqlCmd.Dispose();
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
clsError.LogError(ex);
}

return MailList;

}



public static string GetRootFolderName(Int64 SubFilderID)
{
SqlConnection Conn;
string RouteFolderName = "";
try
{

Conn = new SqlConnection(Common.ConnectionString);
Conn.Open();
SqlCommand sqlCmd = new SqlCommand("GetRouteFolderbyRouteFolderId", Conn);
sqlCmd.CommandType = CommandType.StoredProcedure;

sqlCmd.Parameters.Add(new SqlParameter("@SubFolderId", SqlDbType.Int));
sqlCmd.Parameters["@SubFolderId"].Value = SubFilderID;



SqlDataAdapter da = new SqlDataAdapter(sqlCmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
RouteFolderName = Convert.ToString(dt.Rows[0]["RouteFolderName"]);
}
Conn.Close();
sqlCmd.Dispose();
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
clsError.LogError(ex);
}

return RouteFolderName;

}




public static string GetRootFolderNameBySubFolderId(Int64 SubFilderID)
{
SqlConnection Conn;
string RouteFolderName = "";
try
{

Conn = new SqlConnection(Common.ConnectionString);
Conn.Open();
SqlCommand sqlCmd = new SqlCommand("GetRootFolderbySubFolderId", Conn);
sqlCmd.CommandType = CommandType.StoredProcedure;

sqlCmd.Parameters.Add(new SqlParameter("@SubFolderId", SqlDbType.Int));
sqlCmd.Parameters["@SubFolderId"].Value = SubFilderID;



SqlDataAdapter da = new SqlDataAdapter(sqlCmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
RouteFolderName = Convert.ToString(dt.Rows[0]["RouteFolderName"]);
}
Conn.Close();
sqlCmd.Dispose();
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
clsError.LogError(ex);
}

return RouteFolderName;

}


Thanks And Regards.
Kamlesh Nikam


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend