C# 如何创建BLC连接

C# 如何创建BLC连接,c#,sql,C#,Sql,如何创建blConnection(与数据库的连接)这将为变量分配DB连接路径 public class blConnection { private string constr = "Data Source=.\\MSSQLEXPRESS;Initial Catalog=DB_Name;Integrated Security=True"; public string getConstr() { return constr; } } 然后可

如何创建blConnection(与数据库的连接)

这将为变量分配DB连接路径

public class blConnection
{
    private string constr = "Data Source=.\\MSSQLEXPRESS;Initial Catalog=DB_Name;Integrated Security=True";

    public string getConstr()   
    {
        return constr;
    }
}
然后可以在BL类中重用它

public class blCustomerInformation
{
    SqlConnection conn;
    SqlCommand cmd;
    SqlDataAdapter ada;

    blConnection myConn = new blConnection();

    public blCustomerInformation()
    {
        conn = new SqlConnection(myConn.getConstr());
        conn.Open();

        cmd = new SqlCommand();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Connection = conn;

        ada = new SqlDataAdapter();
        ada.SelectCommand = cmd;
    }
}

什么数据库?你需要给我们更多的背景信息!阅读以了解如何使问题变得好,并给它一个回答的机会!BL连接??你找过了吗?你访问过www.ConnectionStrings.com吗?不管怎样,当你在这里提问时,请给出更多的描述。这将有助于我们给您一个更好的答案:)