Hi,
Is it possible to create? What are the pros and cons?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ashish ShuklaRank #458 · 5.5K reputationPosted May 8, 2013, 2:26 AM EDT
I assume you are asking how to create sql statements in c# code.We can definitely
create sql methods dynamically.As it is easy to append strings,so if we have
number of parameters that needs to be passed to the sql string then it is easy to
create sql statements in this way.Though this is not the proper approach since
if we create the procedures for sql statments then it is cached and execution is faster if it needs to be executed later.
Following is an example:
string sql = "select * from table1 where name='" + name + "";
Another disadvantage is sql injection as the end user can easily manipulate the
sql statement strings by giving the wrong inputs intentionally.
So the user can manipulate the sql statment to delete a database table or perform other harmful action.
Suma M161 reputationPosted May 8, 2013, 4:18 AM EDT
Ashish ShuklaRank #458 · 5.5K reputationPosted May 8, 2013, 5:46 AM EDT
that should have the methods for fetching as well as updating the database.
Following steps should help you implement the approach you have said above
1) Create a data access class having the methods for fetching ,updating and deleting records.These should be common methods.
It is better if you create stored procedures corresponding to these methods.
2) Create the entity classes representing the entities or tables in the database.This class should have properties you have mentioned above.
3) Create an instance of the data access class in the step one above.Create the instances of the entity class in the step 2 above and pass the instance of the entity class to the methods of the data access class.You can also assign the result of the data access class method to an entity class instance if you are fetching values.
Suma M161 reputationPosted May 8, 2013, 8:06 PM EDT