I have a search bar with list. The list will display all the suggestions from the database. The problem my search query is not working. I am getting zero count. I am not sure if my query has a correct syntax.
private void NameSearch_SearchButtonPressed(object sender, EventArgs e)
{
var keyword = NameSearch.Text;
var db = DependencyService.Get<ISQLiteDB>();
var conn = db.GetConnection();
var getCaf = conn.QueryAsync<ContactsTable>("SELECT FileAS FROM tblContacts WHERE FileAs LIKE '%?%'", keyword);
var resultCount = getCaf.Result.Count;
if (resultCount > 0)
{
var result = getCaf.Result;
lstName.ItemsSource = result;
}
}
In your Query, it contains "FileAS" and "FileAs" case sensitivity issue. Make sure they both are same and exactly like the column name.
Change your Query to:
conn.QueryAsync<ContactsTable>($"SELECT FileAS FROM tblContacts WHERE FileAS LIKE '%{ keyword }%'").ToList();
OR
To reduce spelling mistakes you can try following Lambda Expression as Query:
conn.Table<ContactsTable>().Where(x => x.FileAS.Contains(keyword)).ToList();
So, Your Final Code should look like:
private void NameSearch_SearchButtonPressed(object sender, EventArgs e)
{
var keyword = NameSearch.Text;
var db = DependencyService.Get<ISQLiteDB>();
var conn = db.GetConnection();
var getCaf = conn.Table<ContactsTable>().Where(x => x.FileAS.Contains(keyword)).ToList();
var resultCount = getCaf.Count();
if (resultCount > 0)
{
lstName.ItemsSource = getCaf;
}
}
Hope this will solve your issue.
Related
I am updating data and then I am adding them back to my list. However if I pres the update button few times on the row I will get the same line repeated few times. Can you please help how to add updated data without duplication?
First I remove
private void OnItemSelected(DocumentData selectedItem)
{
var index = Results.IndexOf(selectedItem);
Results.Remove(selectedItem);
Navigation.PushPopupAsync(new EditPopUp(selectedItem, this, index));
}
And then I update
public void UpdateValue(DocumentData selectedItem, int index)
{
var detail = new DocumentData()
{
FieldValue = selectedItem.FieldValue,
FieldDescriptor = selectedItem.FieldDescriptor,
Size = LoadSize(),
Padding = LoadPadding(),
};
Results.Insert(index, detail);
}
check for the existence of a matching item before you insert
var exists = Results.Any(r => r.FieldValue == selectedItem.FieldValue && r.FieldDescriptor == selectedItem.FieldDescriptor);
if (!exists) {
var detail = new DocumentData()
{
FieldValue = selectedItem.FieldValue,
FieldDescriptor = selectedItem.FieldDescriptor,
Size = LoadSize(),
Padding = LoadPadding(),
};
Results.Insert(index, detail);
}
i want to get data from web api in listview with paging. What i have done so far i dont see any problem in my code but i am getting null values in Handle_OnDemandLoading
private FeaturedItemList products = new FeaturedItemList();
protected async void FeaturedList()
{
var httpClient = new HttpClient();
var json = await httpClient.GetStringAsync("http://orangepotato.rjcpacking.com/index.php?route=api/login/getFeaturedProducts");
products = JsonConvert.DeserializeObject<FeaturedItemList>(json);
dataPager.Source = products.products;
}
void Handle_OnDemandLoading(object sender, Syncfusion.SfDataGrid.XForms.DataPager.OnDemandLoadingEventArgs e)
{
var source= products.products.Skip(e.StartIndex).Take(e.PageSize);
FeaturedlistView.ItemsSource = source.AsEnumerable();// here is i am getting null values but i am getting values in datapager.source
}
I am trying to query orders and update them. I have been able to isolate my problem in a unit test:
[Fact(DisplayName = "OrderDocumentRepositoryFixture.Can_UpdateAsync")]
public async void Can_UpdateByQueryableAsync()
{
var order1 = JsonConvert.DeserializeObject<Order>(Order_V20170405_133926_9934934.JSON);
var orderId1 = "Test_1";
order1.Id = orderId1;
await sut.CreateAsync(order1);
foreach (var order in sut.CreateQuery())
{
order.Version = "myversion";
await sut.UpdateAsync(order);
var ordersFromDb = sut.GetByIdAsync(orderId1).Result;
Assert.Equal("myversion", ordersFromDb.Version);
}
}
where :
public IQueryable<T> CreateQuery()
{
return _client.CreateDocumentQuery<T>(UriFactory.CreateDocumentCollectionUri(_databaseId, CollectionId));
}
With this code, orders are not updated.
If I replace the CreateQuery() by what follows, it does work:
[Fact(DisplayName = "OrderDocumentRepositoryFixture.Can_UpdateAsync")]
public async void Can_UpdateByQueryableAsync()
{
var order1 = JsonConvert.DeserializeObject<Order>(Order_V20170405_133926_9934934.JSON);
var orderId1 = "Test_1";
order1.Id = orderId1;
await sut.CreateAsync(order1);
var order = sut.GetByIdAsync(orderId1).Result;
order.Version = "myversion";
await sut.UpdateAsync(order);
var ordersFromDb = sut.GetByIdAsync(orderId1).Result;
Assert.Equal("myversion", ordersFromDb.Version);
}
where
public async Task<T> GetByIdAsync(string id)
{
try
{
var documentUri = UriFactory.CreateDocumentUri(_databaseId, CollectionId, id);
var document = (T) await ((DocumentClient) _client).ReadDocumentAsync<T>(documentUri);
return document;
}
catch (DocumentClientException e)
{
if (e.StatusCode == HttpStatusCode.NotFound) return null;
throw;
}
}
I've been trying to understand why this doesn't work. Obviously i could always do a GetByIdAsync before updating, but that seems overkill?
What can't I see?
Thanks!
You create your query, but you never execute it (CreateDocumentQuery just sets up the query). Try altering your call to something like:
foreach (var order in sut.CreateQuery().ToList())
{
//
}
Also note: if you are always querying for a single document, and you know the id, then ReadDocumentAsync() (your alternate code path) will be much more effecient, RU-wise.
I want to show a list on an .aspx site. Therefore I have to use the SP client object model.
I found the following tutorial, but this doesn't use the client libraries:
http://social.technet.microsoft.com/wiki/contents/articles/30287.binding-gridview-with-sharepoint-list.aspx
My code so far looks the following:
ClientContext clientContext = GetContext(accessToken);
Web web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();
// Get the email input list.
List inboxList = web.Lists.GetByTitle("InboxList");
Microsoft.SharePoint.Client.ListItemCollection items = inboxList.GetItems(new CamlQuery());
clientContext.Load(inboxList);
clientContext.Load(items, ic => ic.Include(i => i["DisplayName"], i => i["Client_Title"], i => i["HasUniqueRoleAssignments"]));
clientContext.ExecuteQuery();
foreach (Microsoft.SharePoint.Client.ListItem i in items)
{
clientContext.Load(i);
}
clientContext.ExecuteQuery();
oGrid.DataSource = items;
oGrid.DataBind();
But this shows only some "meta data" of the list item collection, see screenshot:
If I use oGrid.DataSource = inboxList; I get an InvalidOperationException because the data source isn't type of IListSource, IEnumerable nor IDataSource.
If I use oGrid.DataSource = inboxList.DataSource; I get an PropertyOrFieldNotInitializedException, but I don't know how to load this attribute (via clientContext.Load it didn't work)?!
I got it - works with following code:
protected void Page_Load(object sender, EventArgs e)
{
...
ClientContext clientContext = GetContext(accessToken);
Web web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();
// Get the email input list.
List inboxList = web.Lists.GetByTitle("InboxList");
Microsoft.SharePoint.Client.ListItemCollection items = inboxList.GetItems(new CamlQuery());
clientContext.Load(inboxList);
clientContext.Load(items);
clientContext.ExecuteQuery();
foreach (Microsoft.SharePoint.Client.ListItem i in items)
{
clientContext.Load(i);
}
clientContext.ExecuteQuery();
oGrid.DataSource = GetInboxListData(inboxList, items);
oGrid.DataBind();
}
else if (!IsPostBack)
{
Response.Write("Could not find a context token.");
return;
}
}
private DataTable GetInboxListData(List inboxList, Microsoft.SharePoint.Client.ListItemCollection items)
{
DataTable dt = new DataTable();
dt.Columns.Add("From");
dt.Columns.Add("To");
dt.Columns.Add("Subject");
dt.Columns.Add("Body");
dt.Columns.Add("Attachments");
dt.Columns.Add("Sent");
DataRow row;
foreach(Microsoft.SharePoint.Client.ListItem item in items)
{
row = dt.Rows.Add();
row["From"] = item["From1"].ToString();
row["To"] = item["To"].ToString();
row["Subject"] = item["Subject1"].ToString();
row["Body"] = item["Body1"].ToString();
row["Attachments"] = item["Attachments"].ToString();
row["Sent"] = item["Sent"].ToString();
}
return dt;
}
This is similar to Retrieve the values from a list to Gridview in SharePoint Webpart? but with client object model methods & objects.
I have an error in the binding Of The Telerik RadScheduler I need help. The error is
DataBinding: 'Calender.Model.RadSchedulerData' does not contain a property with the name 'ID'.
I want to know what is the problem? I make alot of search but I do not get the right answer. Please any one know this error please tell me, Thanks.
protected void Page_Load(object sender, EventArgs e)
{
List<RadSchedulerData> lstrsd = new List<RadSchedulerData>();
NewCalenderDBEntities1 Context = new NewCalenderDBEntities1();
int UserID = int.Parse(Request.QueryString["UserID"]);
//int UserID = 1;
Session["UserID"] = UserID;
var Data = (from r in Context.Users
where r.ID == UserID
select new { AppointmentTbl = r.Appointments }).ToList();
var D = (from r in Context.Appointments
where r.RoleId == 1
select new RadSchedulerData { Subject = r.Subject, StartDate = r.Start, EndDate = r.End }).ToList();
lstrsd.AddRange(D);
foreach (var item in Data)
{
foreach (var i in item.AppointmentTbl)
{
var DD = Context.Appointments.Where(w => w.RoleId == 2 && w.ID == i.ID).Select(s => new RadSchedulerData
{
Subject = s.Subject,
StartDate = s.Start,
EndDate = s.End
}).ToList();
lstrsd.AddRange(DD);
var AllSharedData = Context.Appointments.Where(w => w.RoleId == 3 && w.ID == i.ID).Select(s => new RadSchedulerData
{
Subject = s.Subject,
StartDate = s.Start,
EndDate = s.End
}).ToList();
lstrsd.AddRange(AllSharedData);
}
}
RadScheduler1.EnableCustomAttributeEditing = true;
RadScheduler1.DataKeyField = "ID";
RadScheduler1.DataSource = lstrsd;
RadScheduler1.DataBind();
}
If you read the error message carefully again, you will probably see the problem by yourself:
DataBinding: 'Calender.Model.RadSchedulerData' does not contain a property with the name 'ID'.
It simply means that the control is trying to fetch a value for the property ID on the RadSchedulerData class and it cannot find it. This could mean, it doesn't exist or that it is not public.
The reason the control is trying to read that specific property on that class is because in the code sample, the DataSource property of the RadScheduler is set to a List<RadSchedulerData> and its DataKeyField property to ID.
To fix the binding error, you either
create (and populate) an ID property in the RadSchedulerData class
make the ID property public in the RadSchedulerData class
give the RadScheduler.DataKeyField a different property name that exists in RadSchedulerData
change the RadScheduler.DataSource property to a list of other object types that have an ID property .