i got a sqlite db with some values, one of it is called "NWPrice". i want to Sum() the price, so i can put it into a string(label) later on. its like in a normal online shop, you got some stuff with a price and its added to "summe" in the end. (dont worry, its not a real shop, was just an exampel). so here is the code i got( i tried it in 2 ways, so thats why there are "summe" and "z"):
var summe = await _connection.QueryAsync<Bestellung>("SELECT SUM(NWPrice) FROM Bestellung");
var z = summe.ToList().FirstOrDefault();
SummeEinkauf.Text = summe.ToString();
Summenlabel.Text = z.ToString();
and the outcome for z its writing "Projektname.PackegeName" and for summe its writing "system.collections.generic.list´1[projektname.models.classname]"
can you help me :D?
by the way(found this allready here):
var ent = conn.Table<Transaction>().Where(t => t.price > 0);
entLabel.Text = (ent.Sum(t => t.price)).ToString();
this one doesnt work, it says it cant convert a string to a bool in the "where-
clinches"
Finally here´s an answer:
var ent = await _connection.ExecuteScalarAsync<int>("SELECT SUM(NWPreis) FROM BESTELLUNG");
SummeEinkauf.Text = ent.ToString();
if there s anybody who can tell me (exactly for my case) how i can write the answer in this format "0.00" and not (like it is now) in thie "0" or this "0.0" it would be grat. but the most is done :)
Related
How do I get the total results of a query that returns more than the limit?
I think that SQL API v2 had RetrievedDocumentCount in its QueryMetrics-object
https://learn.microsoft.com/sv-se/azure/cosmos-db/profile-sql-api-query#linq-on-documentquery
But I can't find that in v3. You use an iterator instead, so the code is very different. There is an Diagnostics-property but it does not seem to contain what I need.
IOrderedQueryable query = _container.GetItemLinqQueryable<T>();
FeedIterator<T> iterator = query.Limit(10).ToFeedIterator();
var documents = new List<T>();
while (iterator.HasMoreResults)
{
var currentResultSet = await iterator.ReadNextAsync();
var count = currentResultSet.Diagnostics.GetTotalResultsHerePlease();
documents.AddRange(currentResultSet);
}
I assume query is your IQueryable<>? (Please don't use var in pasted code, it really helps to be able to read the types.) In that case you can get the count by
int totalCount = await query.CountAsync();
See documentation here.
I have a table with a column of icons. Each Icon has a class of "test" and then "test" + [some rating]. The rating could be A, B, C, XX, YY. I'd like to select the group of icons and loop over them, pop off the last class (the one with the rating) and then expect that my Set of classConsts contains the class in question. I've done a bunch of research but can only find examples of interacting with each of the elements, I'm not sure what I'm doing wrong when trying to check the classes on each instead. Any help is appreciated, thanks.
The below code blows up when i call mrArray.nth saying it's not a function (sorry its a bit messy, had to change some variable names around)
test('Sers are verified', async t => {
const IconArr = Selector('#testtable .test');
var count = await IconArr().count;
var myArray = await IconArr();
const classConsts = ["testClassA", "testClassB", "testClassC", "testClassXX", "testClassYY"]
let mySet = new Set(classConsts);
for(let i = 1; i <= count; i++){
console.log(mySet.has(myArray.nth(i).classNames.pop()));
};
});
myArray is no longer a Selector object after you execute it as an asynchronous function. Please refer to the following help article for more information DOMNodeState.
Also, the index starts with 0, not 1. Your code may look as follows:
for(let i = 0; i \< count; i++){
let classes = await IconArr().nth(i).classNames;
console.log(mySet.has(classes.pop()));
};
You can always debug your test cases to see what goes wrong:
https://devexpress.github.io/testcafe/documentation/recipes/debugging/chrome-dev-tools.html
I'm trying to create two spreadsheets: one tracks student attendance at school, the other tracks their attendance at Track practice. The goal is to write a function, that I can set up as a button, that I can click that will automatically send emails to several people if the student is present at school but is absent for sports without getting excused.
Right now, the whole thing is working pretty well, but I have one issue. I have a column that will read "Good" or "Bad" depending on whether the student meets the above condition. The function turns these into an array. I would like to use the index of the "Bad"'s to find the necessary email addresses, which are stored at the same index point in another array that I make from the spreadsheet. I'm not sure how to save this index point and use it to reference the email addresses. Code below.
function sendEmailsMonday() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("TrackAttendance");
var dataRange = sheet.getRange("D2:D30");
var data = dataRange.getValues();// Gets array of "Good" and "Bad"
for (i in data) {
if(i = "Bad") {
var place = data.indexOf(i);
var dataRange2 = sheet.getRange("M2:M30");// Gets array of email addresses
var data2 = dataRange2.getValues();
var emailAddress = data2[place];
var message = "This is an automated email informing you that your child/advisee ____ was present at school today, but missed Track without being excused. Feel free to email Mr. # with any questions.";
var subject = "___ missed Track Practice";
MailApp.sendEmail(emailAddress, subject, message);
return;
}
}
}
So, the issue comes in with the index lines. If I get rid of
var place = data.indexOf(i);
and replace
var emailAddress = data[place];
with
var emailAddress = data[28];
or any other number, it will grab the email address and send it. But then it has nothing to do with the values in the other column.
Seems like this should be an easy fix but I'm bad at this.
Very late responding now. I think you are almost there.
Your IF statement should read:
if(i == "Bad") {
And then replace 'place' with i:
var emailAddress = data2[i];
It should work as expected now.
I work in unity and I am using parse.com to save my game score.But I'm getting a problem that I'm not able to get top ten score. Here the following code I'm using,
var query = ParseObject.GetQuery ("GameScore").OrderByDescending("score").Limit(5);
query.FindAsync().ContinueWith(t =>
{
IEnumerable<ParseObject> comments = t.Result;
foreach (var obj in comments) {
int score = obj.Get<int>("score");
Debug.Log(score);
string playerName = obj.Get<string>("playerName");
Debug.Log(playerName);
bool cheatMode = obj.Get<bool>("cheatMode");
Debug.Log("cheatmode"+cheatMode);
}
});
when I run this code the "foreach" loop runs only once, But I have save six rows in my class(over the parse.com server side).
I don't know why it is not responding. Please help me.
Thanks
I'm new to F# and trying to dive in first and do a more formal introduction later. I have the following code:
type Person =
{
Id: int
Name: string
}
let GetPeople() =
//seq {
use conn = new SQLiteConnection(connectionString)
use cmd = new SQLiteCommand(sql, conn)
cmd.CommandType <- CommandType.Text
conn.Open()
use reader = cmd.ExecuteReader()
let mutable x = {Id = 1; Name = "Mary"; }
while reader.Read() do
let y = 0
// breakpoint here
x <- {
Id = unbox<int>(reader.["id"])
Name = unbox<string>(reader.["name"])
}
x
//}
let y = GetPeople()
I plan to replace the loop body with a yield statement and clean up the code. But right now I'm just trying to make sure the data access works by debugging the code and looking at the datareader. Currently I'm getting a System.InvalidCastException. When I put a breakpoint at the point indicated by the commented line above, and then type in the immediate windows reader["name"] I get a valid value from the database so I know it's connecting to the db ok. However if I try to put reader["name"] (as opposed to reader.["name"]) in the source file I get "This value is not a function and cannot be applied" message.
Why can I use reader["name"] in the immediate window but not in my fsharp code? How can I use string indexing with the reader?
Update
Following Jack P.'s advice I split out the code into separate lines and now I see where the error occurs:
let id = reader.["id"]
let id_unboxed = unbox id // <--- error on this line
id has the type object {long} according to the debugger.
Jack already answered the question regarding different syntax for indexing in F# and in the immediate window or watches, so I'll skip that.
In my experience, the most common reason for getting System.InvalidCastException when reading data from a database is that the value returned by reader.["xyz"] is actually DbNull.Value instead of an actual string or integer. Casting DbNull.Value to integer or string will fail (because it is a special value), so if you're working with nullable columns, you need to check this explicitly:
let name = reader.["name"]
let name_unboxed : string =
if name = DbNull.Value then null else unbox name
You can make the code nicer by defining the ? operator which allows you to write reader?name to perform the lookup. If you're dealing with nulls you can also use reader?name defaultValue with the following definition:
let (?) (reader:IDataReader) (name:string) (def:'R) : 'R =
let v = reader.[name]
if Object.Equals(v, DBNull.Value) then def
else unbox v
The code then becomes:
let name = reader?name null
let id = reader?id -1
This should also simplify debugging as you can step into the implementation of ? and see what is going on.
You can use reader["name"] in the immediate window because the immediate window uses C# syntax, not F# syntax.
One thing to note: since F# is much more concise than C#, there can be a lot going on within a single line. In other words, setting a breakpoint on the line may not help you narrow down the problem. In those cases, I normally "expand" the expression into multiple let-bindings on multiple lines; doing this makes it easier to step through the expression and find the cause of the problem (at which point, you can just make the change to your original one-liner).
What happens if you pull the item accesses and unbox calls out into their own let-bindings? For example:
while reader.Read() do
let y = 0
// breakpoint here
let id = reader.["id"]
let id_unboxed : int = unbox id
let name = reader.["name"]
let name_unboxed : string = unbox name
x <- { Id = id_unboxed; Name = name_unboxed; }
x