CRUD Operations in C# — part II

Maleesha Wickramarathna
2 min readApr 24, 2021

In here I am going to do some Modifications to Connection class. We can use 2 methods to do all CRUD operations without code again and again.

As you all know always we pass some string value to the server to do all modifications.

As an example : When we want to get all values from particular table , We Use “ SELECT * FROM <table_name>;”

Here I’m doing all critical parts inside the method and get SQL statement as the method parameter.

For Insert , Update, Delete

Here I am using a static method with boolean return type. I can do Insert, Update, Delete operations using this method. The only thing I have to do here is passing a correct SQL statement.

In here what I am doing is,

  • try to open the connection.
  • and I try to create a new SQLCommand using SQL statement and connection.
  • after try to SQLCommand using executeScalar() method.

For Get all or Specific Record

In here also have to pass SQL statement . after sending that this will return particular record or records as a DataTable.

Let discuss How to do CRUD operations using these two methods in the next post.

--

--

Maleesha Wickramarathna

I am a 3rd-year Software Engineering undergraduate at the Sri Lanka Institute of Information Technology- SLIIT ,Reg.no :IT19004778