Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to create common class for application in which i can create some methods for ado.net code. And I can access that methods in any c# file belongs to my project or application. Currently I am writing connectivity code on every c# file.
Please let me know the Idea with example
.
Posted

First of all don't store an open connection in a common class. It's better to open and close the connection during one call.

But what comes to the class itself, why not create a static class which doesn't need to be instantiated. So simply

C#
internal static class MyConnectionUtils [
   // here goes your methods
}


And when using it
C#
void MyMethod(SqlConnection connection) {
   // do something
   MyConnectionUtils.SomeMethod(connection);
   // do something
}
 
Share this answer
 
Comments
DamithSL 24-Jul-15 1:01am    
Wendelius 24-Jul-15 1:10am    
Yes, those would probably be handy. But because the OP didn't explain what kind of functionality he's going to write I have no idea Data Access Application Block contains what he needs :)

Anyhow, thanks for pointing out!
DamithSL 24-Jul-15 1:33am    
Yes, agreed. my5!
Wendelius 24-Jul-15 1:38am    
Thanks :)
DamithSL 24-Jul-15 1:39am    
you got my vote? it seems bug in CP, when I click on vote button it redirect to blank page.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900