如果我有幾個類在同一頁上使用相同的連接字符串,我應該保持連接open();
並關閉它,一旦我完成或繼續打開和關閉。保持連接字符串是否打開c#
下面的例子
protected void Page_Load(object sender, EventArgs e)
{
cs.Open();
something ...
cs.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
cs.Open();
something .....
cs.Close();
}
或本
protected void Page_Load(object sender, EventArgs e)
{
cs.Open();
something ...
}
protected void Button1_Click(object sender, EventArgs e)
{
something .....
cs.Close();
cs.Dispose();
}