5 votes

Ideal ways for Choosing DataSet or DataTable

As pointed out by @iSR5's comment, A DataSet is basically a wrapper around a collection or DataTable objects. It has some other ...
Chris Schaller's user avatar
5 votes
Accepted

Undo/Redo Functionality in DataGridView c#

Review Welcome to Code Review. There are few suggestions as below. Layout and formatting Not sure why many newlines between the curly brackets and the method definition, ...
JimmyHu's user avatar
  • 4,708
4 votes
Accepted

Search DataTable by column for a specific row

I have two suggestions: Trim ColValue once rather than every iteration through the loop. Use a case-insensitive string compare rather than performing ...
Jesse C. Slicer's user avatar
3 votes

Querying employee schedules in a month

I'm going to try to avoid raging about the data table based data access layer because I doubt a random person on the internet is going to change the direction of your project. So, let's look at your ...
RobH's user avatar
  • 16.9k
3 votes

Building equal number of records list object

Try following some simple rules: Avoid setting flags in loops. Try calculating the data you need before taking action. Only increment counters inside loop declaration. This way even if something gets ...
jakubiszon's user avatar
3 votes
Accepted

Add data to DataTable

params (version 1) You can use the same trick the Rows.Add method uses namely the params keyword By using the params keyword, ...
t3chb0t's user avatar
  • 44.3k
3 votes
Accepted

Constructing file paths for each row of a datatable in C#

One simple trick here would be to take the column processing outside of the row processing (the column metadata should not change while the rows probably will): ...
Jesse C. Slicer's user avatar
3 votes

Grouping and summing values for food takeout

Scope If all you need is to calculate some values from a set of data tables, it would suffice to use LINQ. However, if you prefer to provide an API with common functionality concerning orders and ...
dfhwze's user avatar
  • 13.9k
3 votes
Accepted

How to generate Datarows based on a delimiter in a Datacolumn from a DataTable in C#

Move code to methods. By the time you hit for (int j = counter; j < newTable.Rows.Count;) you're nearly ten levels deep. Not only are you losing valuable screen ...
BCdotWEB's user avatar
  • 11.2k
2 votes
Accepted

Rolling up Invoice Items Matching Certain Criteria

I noticed that you have a section of code where a boolean variable floats out of a foreach loop and into the next if statement, but you can remove the if statement, and the boolean variable. Here ...
Malachi's user avatar
  • 28.6k
2 votes

List<List<string>> vs DataTable

Don't loop - join Often I need to 'cross-reference' these tables to get the correct values. That's what joins are for. Use them instead of iterating with two loops to get the results e.g. ...
t3chb0t's user avatar
  • 44.3k
2 votes
Accepted

List of classes to datatable

Cases like this I would hide the "sloppy" I would create a class that holds the mappings from the class to the table and create methods to build the mappings. This way there is no need for ...
CharlesNRice's user avatar
  • 4,343
2 votes
Accepted

Vertical & Horizontal Direction of a DataTable

I like that you have an actual method, instead of a bunch of code in Main. This makes is easier to reuse, segment changes, and test. Passing in a string for ...
Brian J's user avatar
  • 351
2 votes

Making a list of customers who buy the top N items from a supplier

My eye started twitching uncontrollably when I saw .Where(x => x.SupplierID == supplier.ToUpper()). To me, this indicates a major design flaw: something that's ...
BCdotWEB's user avatar
  • 11.2k
2 votes
Accepted

Return a paged DataTable

Parameter validation Because GetErrorLog() is a public method you should assume that any given parameter can be wrong so a at least basic validation should take ...
Heslacher's user avatar
  • 50.4k
2 votes

Calculating the total of each column and display in footer of gridview in DataTable

#region column sum and show in footer Before you start optimizing this block you should move it into a separate method. The ...
t3chb0t's user avatar
  • 44.3k
1 vote

Building equal number of records list object

Because this function is presented w/out a context to adequately test the code in, i.e. with sample data, a Main function, etc., the best way to critique this ...
T145's user avatar
  • 3,099
1 vote

DataTable runtime grouping on user defined criteria

This is what I ended up with. I removed the meaningless dictionary and replaced it with a CompositeKey. I need additional processing for the values thus the ...
t3chb0t's user avatar
  • 44.3k
1 vote
Accepted

DataTable runtime grouping on user defined criteria

Honestly, I am not sure if a dictionary is the right data structure for realizing composed keys. At least for me it is not directly obviously how the data are grouped. I think the main issue that ...
JanDotNet's user avatar
  • 8,538
1 vote
Accepted

Populate DataTable with API results

You can pass all of the properties of your dataPull class in a single line which will also pass any future properties you decide to add to your object, using ...
Denis's user avatar
  • 8,458
1 vote

C# SQL query builder to fill DataTable

The code that queries the database and returns sick days, holidays, working days, has a pattern to it. The code sets parameters, runs scalar/datatable query, sets parameters... and so forth. I'm ...
null's user avatar
  • 221
1 vote

C# SQL query builder to fill DataTable

I can't really help with the performance issue because following your code is really hard (I don't speak the language it's in). That said, I just can't look at this and say nothing: ...
RobH's user avatar
  • 16.9k
1 vote
Accepted

Merge two DataTables by adding corresponding entries

Naming of methods and variables I don't like them. What is dt3? What is dt4? Why are you calling the variable r3 and c3? Why not name them by what they represent? Also the name of the method I feel, ...
BenKoshy's user avatar
  • 1,011
1 vote

Merge two DataTables by adding corresponding entries

You are not testing for same size. You don't use combinedDT34. You are changing an input which is not a good practice. I am not sure if dt3 will be passed by ...
paparazzo's user avatar
  • 5,976
1 vote
Accepted

Querying employee schedules in a month

First, create index on your table as @RobH suggestion CREATE INDEX IX_ScheduleList_Id_Date on your_schema.ScheduleList ( Id, Date, Shift ) Then as @...
nyongrand's user avatar
  • 116
1 vote

Querying employee schedules in a month

DateTime dt = (DateTime)sqlReader["Date"]; This is faster ...
paparazzo's user avatar
  • 5,976
1 vote

Constructing file paths for each row of a datatable in C#

string is immutable newfileName += row[col].ToString() + "_"; is inefficient ...
paparazzo's user avatar
  • 5,976

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