I have a list of items with different ids which represent a SQL table’s PK values. Is there any way to build an efficient and safe statement? Since now I’ve always prepared a string representing the statement and build it as I traversed the list via a foreach loop. Here’s an example of what I’m doing: Which feels very unsafe
Tag: ado.net
ADO.NET: Send procedure parameter with null value
I need to send a parameter a null value to the procedure, but I get an error: System.Data.SqlClient.SqlException: ‘Procedure or function ‘sel_mizanyeni’ expects parameter ‘@subeno’, which was not supplied.’ When I run the same procedure with the same parameters in SQL Server, it does not cause an error. When I run it with ADO.NET in C#, I get that error.
How to get output parameter and also a table when executing a stored procedure
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
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 to delete only Top 100 rows which are older than 30 days from current date in C#? [closed]
Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed 6 months ago. Improve this question When I execute following query , it is executed properly in SSMS but same query in code does not delete anything and 0 rows are affected from
How to connect sql Database with ado.net in Asp.Net Core Mvc 5.0?
I can not find where am i missing. my code like this ; users.cs : } usersAccessLayer.cs ; appsettings.json And finally i got this error; An unhandled exception occurred while processing the request. NullReferenceException: Object reference not set to an instance of an object. Adonet_Sql.Models.users..ctor() in users.cs, line 14 Adonet_Sql.Models.users..ctor() in users.cs bla bla. Answer ConfigurationManager.ConnectionStrings[“DefaultConnection”].ConnectionString; is for .net Core
Query not executing as expected, returns -1 no matter what
I’m working on a user login system for a semester final. I am using C# in Visual Studio with ADO.NET. I have a query that I use on a database table named Credentials: SELECT * FROM Credentials WHERE …
Getting Error as @Parameter1 is not a parameter for procedure
I am learning mvc from this video where I am getting data from a form and saving it to database. When I ran my code first it gave an error stating Procedure or function ‘spAddEmployee’ expects parameter ‘@Employee_Name’, which was not supplied. I followed a solution in which I initialized my stored procedure as NULL but now I am getting
Unexpected token when creating a string expression?
I have the following code: There is an error here ‘{cardId And it tells me Invalid Expression term ” Answer You need to be aware that this kind of string concatenation is avoided and it is open to SQL Injection attack, you should always use parameterized queries to avoid SQL Injection and also to get rid of errors, something like
Incorrect number of arguments for PROCEDURE… from C#
I am having trouble using parameters in a stored procedure. I believe I am not passing the parameters in correctly with the C#. My code is roughly equivalent to: public static string GetCustomer(…