Skip to content
Advertisement

Tag: c#

How to get the average of a column in MySQL

I’m trying to find a way to calculate the average of a column (as a double/float or decimal). I’ve found the AVG function in MySQL documentation but I can’t get it to work. Currently I’ve got the following code: Now for some reason this does not work. It returns “Unable to cast object of type ‘System.Int64’ to type ‘System.Double’.” The

How to combine multiple INSERT INTO’s with prepared statements?

Using Dapper, is there a way to form this into one query with the prepared statements? The length of userIds is dynamic. Answer One of the many advantages of Dapper over straight ADO.NET is the simplicity of inserting a list of data to a table. You just need a list of a class <T> where the properties of the class

Search SQL database with multiple filters

I have the following code: This gives me the rows where “category_id” is equal to the 1. I now want the SELECT statement to return rows where the “category_id” is equal to one of the values I give it. So a simple SELECT statement would look something like this The problem is that I wouldn’t know the values to search

How do I translate this specifik SQL statement to LINQ

SQL: C# Objects: Monitor: And Counter: And the objects that I need to turn it into is: AllStatistics: I don’t have much experience with LINQ so the most I’ve achieved with it is somethig like: My question is, how would I compose an LINQ statement with the same functionality of the above SQL query ? Answer It looks like you

Parameter returning not in the correct format

I have an async task method that queries a database table for the total amount of Credits in a specific column. I have a string parameter in the method that I use for the query to identify which user is logged in, which is stored in Properties.Settings.Default.Student_Number;. The column for the student number in the database is a varchar and

Advertisement