14 votes

C# function to execute queries in a SQL Server database

SqlConnection implements the IDisposable interface, and so does the SqlDataAdapter class - ...
Mathieu Guindon's user avatar
13 votes

C# function to execute queries in a SQL Server database

There are two problems with this that are immediately apparent: You are executing arbitrary SQL. This is a SQL Injection flaw. You'll want to use parameterized queries. You are catching an exception ...
Greg Burghardt's user avatar
6 votes

ADO.NET database access layer

I suggest using a light-weight ORM called Dapper. Hides all the dirty work by providing extension methods over ADO.NET. Take a look at the examples here: http://dapper-tutorial.net/execute
amassani's user avatar
5 votes

Handle IDisposable objects

So I can reuse the InvokeSql and do not have to bother about the disposing. Sure. Except InvokeSql is private, so reuse is ...
Mathieu Guindon's user avatar
4 votes

Data Access Layer to return Data Transformation object

(See also comments in code) GetRefNo Create case-insensitive dictionaries right away as you ignore the case later anyway: ...
t3chb0t's user avatar
  • 44.3k
4 votes
Accepted

ADO.NET Wrapper

using (cnn = NewConnection()) {} This is a very dangerous design. Especially the private TConnection cnn field that is shared ...
t3chb0t's user avatar
  • 44.3k
4 votes

Extremely basic login system in console

Disclaimer: my first post here and I'm not C# programmer If the input is different, the function will of course call itself again (that's why it is a recursive one, right?) This is dangerous, as ...
Noone AtAll's user avatar
3 votes

Extremely basic login system in console

Recusion Abuse This does not seem to be a naturally recursive problem and using recursion here causes more issues than it is worth: If the user enters too many invalid inputs, they can blow the ...
Derek Husky's user avatar
3 votes

ADO.NET database access layer

1. Alternatives Just as the other answer suggests, you should be looking into existing framework. There's no use reinventing the wheel unless you're specifically trying to improve it (which is not ...
Flater's user avatar
  • 5,542
3 votes

Extremely basic login system in console

All in all, you did quite well. If you have the option, I'd recommend letting a system like Active Directory handle user credentials rather than storing and validating themselves. However, as there's ...
Merkle Groot's user avatar
3 votes

Unit of Work (UoW) pattern with ADO.NET

you could collapse this piece of code into a single line ...
Malachi's user avatar
  • 28.6k
3 votes
Accepted

Retrieving data in an SQL database and displaying the retrieved data in ASP.NET

Introduction: no one reviewed your code then let me do it, even if after few days. The problem is that you're in the middle of the learning process then many things need to be changed/updated. I won't ...
Adriano Repetti's user avatar
3 votes
Accepted

Generate 10000 matrix barcodes

Strings are immutable so whenever you're concatenating them you're effectively creating new instances every time, this can slow down performance a lot, instead use ...
Denis's user avatar
  • 8,458
3 votes

Handle IDisposable objects

You're making life harder for yourself by not allowing the delegate to have a return type. You could create an overload that accepted a Func instead. ...
RobH's user avatar
  • 16.9k
3 votes

Handle IDisposable objects

There is no need to have a Action<SqlConnection, SqlCommand> parameter if all you need is a SqlCommand object. Selecting ...
Heslacher's user avatar
  • 50.4k
3 votes

Method that fetches rows from database and maps it to a Model class with SqlDataReader

To quote Mark Seemann from the following article Small methods are easy to troubleshoot Write small methods. How small? Small enough that any unhandled exception is easy to troubleshoot. Break the ...
Nkosi's user avatar
  • 3,236
3 votes
Accepted

IPAddress Range access

Quick remarks: There is no point in defining a variable and assigning it a value, only to override that value in the next line (IsRangeEnable in ...
BCdotWEB's user avatar
  • 11.2k
2 votes

Handle IDisposable objects

while (reader.Read()) { User user = new User(); users.Add(user); user.Name = reader["name"] as string; } this doesn't look like good code to me, I ...
Malachi's user avatar
  • 28.6k
2 votes

Handle IDisposable objects

Calling the action is like calling a method. It is executed synchronously. Therefore the using-statement will dispose and end only after the action has done its job. The using-statement does not keep ...
Olivier Jacot-Descombes's user avatar
2 votes
Accepted

ADO.NET transaction handling

FileBulkLoad isn't an ideal name for a method - it's a noun, and nouns should be used for naming types - method names should be verbs, because they do something. ...
Mathieu Guindon's user avatar
2 votes
Accepted

DataReader to To IEnumerable<object[]> To 2 Dimensional Array

The current foreach (IDataRecord record in reader as System.Collections.IEnumerable)... seem complicated for no particular reason and is making assumptions about ...
Nkosi's user avatar
  • 3,236
2 votes

Cancel Long Running Query using Cancellation Token AND SqlCommand.Cancel()

It both cancels the Task as well as cancels the query in SQL Server. I can check the status of the query in SQL Server with ...
Reinderien's user avatar
  • 61.9k
2 votes
Accepted

A Class to Supply an Open Database Connection during the life of a Web Request

As far as I know, in ADO.NET the connection pooling is enabled by default, and if you don't need to pool connections, you'll have to explicitly disable pooling. So,...
iSR5's user avatar
  • 5,248
1 vote
Accepted

Initialize various commands for the SqlDataAdapter

With the following, you'll only add each parameter a single time and just change the command text before assigning it to the adapter command, allowing you to reuse the existing cmd object. ...
Wes H's user avatar
  • 363
1 vote

ADO.NET DAO Layer Design With Base DAO

DataTable has a lot of overhead. In the code you have a lot of overhead. Album AlbumMapper is called for every row and you parse for every column name. I think it would be a lot clean if you ...
paparazzo's user avatar
  • 5,976
1 vote

Simple locale loader

First, since you are concerned about naming: this class doesn't really handle, manage, or control anything. It does two things: queries a database, and makes those results available via a TryGet ...
Pierre Menard's user avatar
1 vote

Ado.Net and Async insert of many rows to db

New command in the loop is wasteful. Create it once and loop on the values. ...
paparazzo's user avatar
  • 5,976
1 vote
Accepted

Implementing RecordSet-like class in C#

In the constructors ...
Heslacher's user avatar
  • 50.4k

Only top scored, non community-wiki answers of a minimum length are eligible