Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to pass connection string to class file. How do i pass that connection to class file.
Posted

1 solution

Create a constructor that takes the connection string as a parameter.


C#
public class classfile
{
    private string _connectionString;
    public classfile(string connectionString)
    {
        _connectionString = connectionString;
    }
}


Now everywhere in your class you can use the '_connectionString' member. (if the methods aren't static)

And everywhere you instantiate your classfile class you'll have to pass the connectionstring.
 
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