Scenario I’m working with SQL Server 2017 (not possible to change) I’m using Visual Studio 2019 in C# console and .NET Framework 4.5 (possible to change) I’m using ADO.NET because several years before we couldn’t use Entity Framework, as the system is made to work with a stored procedure that returns at least 100k rows (possible to change) Situation I
Tag: c#
SSIS Script Task throws Object reference not set to an instance of an object
I am trying to query the database and send the content in the body of the email. When I try to run the package it throws deadlock error. Can anyone please suggest what is that I am missing Script is like below Below is the And the package looks like below.. For every user I need to get all the
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 can I parameterize an SQL table without vulnerability to SQL injection
I’m writing a C# class library in which one of the features is the ability to create an empty data table that matches the schema of any existing table. For example, this: The above code works, but it has a glaring security vulnerability: SQL injection. My first instinct is to parameterize the query like so: But this leads to the
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
It says I am inserting too many values in my columns when I am not? [closed]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 1 year ago. Improve this question
How can I Select list of list or object of object not like a table? (SQL Server)
I have a problem in SQL Server: I want select list of list or object of object not a table. Example : Like a json example : Is there a solution to this problem for me? I want to output a stored procedure that I can use for the web service Answer Given this sample data: You can just apply