filteredrows = Server_Tables[i].Select("Servername='" + searchtext + "'");
The code above compares the data without trimming and selects matched rows.
So how to select rows with trimming?
Try this:
filteredrows = Server_Tables[i].Select("TRIM(Servername) ='" + searchtext.Trim() + "'");
Filter expression used in Datatable.Select supports TRIM function. I've also added Trim() to your entered values since spaces are possible there as well.
Trim searchtext variable;
filteredrows = Server_Tables[i].Select("TRIM(Servername)='%" + searchTerm + "%'");
To trim row values while retrieving with select method you can use;
filteredrows = Server_Tables[i].Select("Servername='%" + searchTerm.Trim() + "%'");
Do you need following;
filteredrows = Server_Tables[i].Select("Trim(Servername)='%" + searchtext.Trim() + "%'");
Related
In Mysql, FIND_IN_SET is used to find value in a set. I have tried FIND_IN_SET in SQLite, but it is not an SQL keyword. I have Googled, but I did not get an answer. If anybody knows, please tell me the alternative to FIND_IN_SET in SQLite.
If you need just a true / false value rather than index then you can use LIKE clause:
(',' || column_name || ',') LIKE '%,value,%'
we can write query like change into hibernate critearea
my old query
select * FROM game_detail WHERE content_id=176 and FIND_IN_SET(12,group_master_id)
New query
select *
FROM game_detail
WHERE content_id=176
and (group_master_id LIKE '%12,%'|| group_master_id LIKE '%,12,'|| group_master_id LIKE '%12')
This is my old query
String query = "SELECT a.content_id,a.content_name,a.image_name,a.image_path,a.rating,d.content_type_name"
+ "from content_master a, category_content_mapping b, "
+ "game_detail c, content_type_master d "
+ "where a.content_id=b.content_id "
+ "and c.content_id = a.content_id "
+ "and a.content_type_id = d.content_type_id "
+ "and b.category_id = '" + category_id + "' "
+ "and find_in_set('" + group_master_id + "',c.group_master_id) "
+ "and a.is_active='Y' and b.is_active = 'Y' and c.is_active = 'Y'"
+ "order by b.content_mapping_id DESC limit 0,3";
Criteria in hibernate use like alternate of find_in_set
Session session=new Configuration().configure().buildSessionFactory().openSession();
Criteria criteria=session.createCriteria(ContentMaster.class);
criteria.setFetchMode("CategoryContentMapping", FetchMode.JOIN);
criteria.setFetchMode("GameDetail", FetchMode.JOIN);
criteria.createAlias("categoryContentMappings","cat");
criteria.createAlias("contentTypeMaster", "ctm");
criteria.createAlias("gameDetails","game");
criteria.add(Restrictions.eq("cat.categoryMaster.categoryMasterId", 9));
criteria.add(Restrictions.disjunction()
.add(Restrictions.like("game.groupMasterId","%12,%"))
.add(Restrictions.like("game.groupMasterId","%,12,%"))
.add(Restrictions.like("game.groupMasterId","%12%")));
criteria.add(Restrictions.eq("isActive", "y"));
criteria.add(Restrictions.eq("cat.isActive", "y"));
criteria.add(Restrictions.eq("ctm.isActive", "y"));
criteria.addOrder(Order.desc("cat.contentMappingId"));
This code shows me null value. In fact I have 4 rows in the grid count, but the problem is that it's showing me null value.
// loops through each row in RadGrid
foreach (GridDataItem row in RadGrid.MasterTableView.Items)
{
Table = Table + row["Columns_Name"].Text.ToString() + " ";
Table = Table + row["My_data_type"].Text.ToString() + " ";
Table = Table + row["Col_Primary_Key"].Text.ToString() + " ";
Table = Table + row["Null_NotNull"].Text.ToString() + "\n,";
}
string value = item.Cells[0].Text; //take the value from the first columns of each row
I have this line of code in asp.net through which inserting date into a table
CMPI_EFF_DATE = cc.GetDataSet("SELECT TRM_EFF_STDT as TRM_EFF_STDT FROM TRM_MST WHERE TRM_CODE = " + ddlTrm.SelectedValue + "").Tables[0].Rows[0]["TRM_EFF_STDT"].ToString(),
and i am using oracle database . but while inserting data into it it show's an error
literal does not match format string
Is ddlTrm.SelectedValue string value? if it's true, I thing you should put value in quotes like this
"'" + ddlTrm.SelectedValue+"'"
Full example:
CMPI_EFF_DATE = cc.GetDataSet("SELECT TRM_EFF_STDT as TRM_EFF_STDT FROM TRM_MST WHERE TRM_CODE = '" + ddlTrm.SelectedValue+"'").Tables[0].Rows[0]["TRM_EFF_STDT"].ToString()
I think you are wrong here ddlTrm.SelectedValue + "")
It should be ddlTrm.SelectedValue )
CMPI_EFF_DATE = cc.GetDataSet("SELECT TRM_EFF_STDT as TRM_EFF_STDT FROM TRM_MST WHERE TRM_CODE = " + ddlTrm.SelectedValue).Tables[0].Rows[0]["TRM_EFF_STDT"].ToString(),
What is the replacement for SetCustomMetaQuery in Broker query Mechanism (Tridion 2011)?
I got lots of help through this post posted by me earlier.
for
query.SetCustomMetaQuery("KEY_NAME='Key' AND KEY_STRING_VALUE >= 'Yes'");
I tried
CustomMetaValueCriteria criteria1 = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("Key"), "Yes");
mainCriteria =CriteriaFactory.And(mainCriteria, criteria1);
query.Criteria = mainCriteria;
But I am stuck at below two examples in one of the filter CTs.
query.SetCustomMetaQuery("(((KEY_NAME='EventStartDate' AND
KEY_DATE_VALUE >= '" + lowerDate + "')) or
((KEY_NAME='EventEndDate' AND KEY_DATE_VALUE >= '" + lowerDate + "')))"")
and
query.SetCustomMetaQuery("KEY_NAME = 'Publication_Issue_Date' and
((convert(varchar(10), key_date_value, 101) = convert(varchar(10),
cast('" + sIssueDate + "' as datetime), 101)) or
key_string_value like '%" + dtIssue[%=nNumber%].Year + "-0" + dtIssue[%=nNumber%].Month + "-" + dDay[%=nNumber%] + "%')");
Could any please help me with this?
Thought I'd have a stab at this so could be way off!
How's this for the first example:
CustomMetaValueCriteria criteria1 = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("EventStartDate"), lowerDate, Criteria.GreaterThanOrEqual);
CustomMetaValueCriteria criteria2 = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("EventEndDate"), lowerDate, Criteria.GreaterThanOrEqual);
OrCriteria or = new OrCriteria(criteria1, criteria2);
Assumes that "lowerDate" is a DateTime.
The second one is a bit confusing, it looks like its checking for the existence of "Publication_Issue_Date" and any KEY_DATE_VALE that equals the sIssueDate variable OR that there's a string metadata value in the from of a date. So is that going to be something like?
CustomMetaKeyCriteria criteria1 = new CustomMetaKeyCriteria ("Publication_Issue_Date")
CustomMetaValueCriteria criteria2 = new CustomMetaValueCriteria(sIssueDate);
AndCriteria andCriteria = new AndCriteria(criteria1, criteria2);
string dt = dtIssue[%=nNumber%].Year + "-0" + dtIssue[%=nNumber%].Month + "-" + dDay[%=nNumber%];
CustomMetaValueCriteria criteria3 = new CustomMetaValueCriteria(dt, Criteria.Like)
OrCriteria or = new OrCriteria(andCriteria, criteria3);
Cheers
Please try with:
CustomMetaValueCriteria criteria1 = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("Key"), "Yes", Criteria.GreaterThanOrEqual);
Let me know if this works.
I want to filter dataset taken to bind report.
my code is something like this
Mohan.Reports.DataSet1 ds1 = DataAccess.TNA_APPROVAL_DATA_FOR_PRINTING_STYLEWISE(DateTime.Now.Date, ddlStyle.SelectedValue);
ds1.Tables[0].Select("StyleNO='" + ddlStyle.SelectedValue + "'");
Reports.CrystalReport1 rp = new Mohan.Reports.CrystalReport1();
//DataRow dt =(DataRow) ds1.Tables[0].Select("StyleNO='" + ddlStyle.SelectedValue + "'");
reportTnaApprovalbyUser.SetDataSource(ds1.Tables[0].DefaultView.RowFilter = "StyleNO='" + ddlStyle.SelectedValue + "'");
CrystalReportViewer1.ReportSource = reportTnaApprovalbyUser;
But Data is not displaying on report. I think filteration is not working....
Please Help