Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# sql insert with a lot of parameters

Tags:

c#

sql

winforms

Is there an elegant way to write an insert statement, which has a lot of parameters? I have like 20 flags that need to be saved in the DB, plus other information that also require to be inserted, along with those 20 flags. Writing a method with 30 parameters for that insert is a waste of time, but so far I haven't come up with other ideas, that might work.

like image 352
Rocshy Avatar asked Dec 21 '22 22:12

Rocshy


2 Answers

You can put all these parameters in an object and pass that object to the method.

like image 94
Sachin Kainth Avatar answered Jan 07 '23 08:01

Sachin Kainth


A standard approach is to create a class representing your entity and then pass around an instance of that class.

This makes it easy to pass to other methods that may do validation, presentation, etc., as well as persistence.

like image 32
D'Arcy Rittich Avatar answered Jan 07 '23 06:01

D'Arcy Rittich