arash691
پنج شنبه 08 فروردین 1392, 17:48 عصر
سلام دوستان ...
چرا بعضی از دستورات رو داخل using مینویسن ؟ بطور مثال به دستور زیر نگاه کنید :
string connection_string = "Data Source=.\\sqlexpress;Integrated Security =yes;";
using ( SqlConnection con =new SqlConnection(connection_string))
{
string Database_Name = textBox1.Text;
SqlCommand com = new SqlCommand("Create DataBase [" + Database_Name + "];", con);
com.Connection.open();
com.ExecuteNonQuery();
}
خب همینطور که میبینید دستورات بالا یک پایگاه داده با نامی که از کاربر میگیره یعنی DataBase_Name بوجود میاره ... ولی سوال اصلی من اینه که چرا دستورات رو درون بدنه using نوشته و اینکه وقتی اینطوری دستورات رو مینویسیم چه تفاوتی با حالتی که از using استفاده نکنیم داره ؟
چرا بعضی از دستورات رو داخل using مینویسن ؟ بطور مثال به دستور زیر نگاه کنید :
string connection_string = "Data Source=.\\sqlexpress;Integrated Security =yes;";
using ( SqlConnection con =new SqlConnection(connection_string))
{
string Database_Name = textBox1.Text;
SqlCommand com = new SqlCommand("Create DataBase [" + Database_Name + "];", con);
com.Connection.open();
com.ExecuteNonQuery();
}
خب همینطور که میبینید دستورات بالا یک پایگاه داده با نامی که از کاربر میگیره یعنی DataBase_Name بوجود میاره ... ولی سوال اصلی من اینه که چرا دستورات رو درون بدنه using نوشته و اینکه وقتی اینطوری دستورات رو مینویسیم چه تفاوتی با حالتی که از using استفاده نکنیم داره ؟