با سلام و تشکر از پاسخ شما
تعریف کلاس ها و مدول ها (کپسوله کردن) را برای هر دو روش می توان به کار برد، در روش دوم چنانچه برنامه تحت شبکه باشد هر بار بخواهیم به بانک اطلاعات (سرور اصلی) وصل بشیم کلی طول میکشه اما از طرفی هم سرور به محض اینکه اطلاعات (رکورد، ...) خودش را به کلایت داد ارتباط اطلاعات قطع میشه و از تراکم کاربران شبکه کم میشه (افزایش کارایی و سرعت سرور)
حال تو حالت اول یک بار وصل میشیم بعد دیگه فقط از سرور استفاده می کنیم فقط این موضوع پیش میاد که سرور مشغوله
توی تعداد زیاد بانک اطلاعاتی روش دوم خوبه
اما توی تعداد بانک اطلاعات کم فکر کنم روش اول بهتر باشه
نمی دانم این خیلی مهم که وقتی سرور را باز کردیم فضایی برای داده ها دوباره اشغال میشه یا فقط زمان فراخوانی رکورد ها به اندازه همان رکوردهای فراخوانی شده حافظه اشغال میشود که با بستن دیتاست یا دیتاریدر این مشکا حل میشه
PublicClassForm1
Dim my_cn AsNew SqlConnection
Dim my_cm AsNew SqlCommand
Dim dr As SqlDataReader
Dim path AsString
Dim strcon AsString
path = "server=(local);database=mydatabase;integrated security=false;" _
& "Persist Security Info=true;User ID=----;Password=-----"
my_cn.ConnectionString = path
my_cn.Open()
PrivateSub Button1_Click(sender AsObject, e As EventArgs) Handles Button1.Click
strcon = "select id from tb where a1 like a2"
my_cm.CommandText = strcon
my_cm.Connection = my_cn
dr = my_cm.ExecuteReader
dr.read()
dim a3 as string=dr("id").ToString
dr.close
strcon = "select id from tb where b1 like b2"
my_cm.CommandText = strcon
my_cm.Connection = my_cn
dr = my_cm.ExecuteReader
dr.read()
dim b3 as string=dr("id").ToString
dr.close
EndSub
PrivateSub Button2_Click(sender AsObject, e As EventArgs) Handles Button2.Click
strcon = "select id from tb2 where a1 like a2"
my_cm.CommandText = strcon
my_cm.Connection = my_cn
dr = my_cm.ExecuteReader
dr.read()
dim c3 as string=dr("id").ToString
dr.close
strcon = "select id from tb2 where b1 like b2"
my_cm.CommandText = strcon
my_cm.Connection = my_cn
dr = my_cm.ExecuteReader
dr.read()
dim d3 as string=dr("id").ToString
dr.close
EndSub
my_cm = Nothing
my_cn.Close()
my_cn = Nothing
end class
یا
PublicClassForm1
PrivateSub Button1_Click(sender AsObject, e As EventArgs) Handles Button1.Click
Dim my_cn AsNew SqlConnection
Dim my_cm AsNew SqlCommand
Dim dr As SqlDataReader
Dim path AsString
Dim strcon AsString
path = "server=(local);database=mydatabase;integrated security=false;" _
& "Persist Security Info=true;User ID=----;Password=-----"
my_cn.ConnectionString = path
my_cn.Open()
strcon = "select id from tb where a1 like a2"
my_cm.CommandText = strcon
my_cm.Connection = my_cn
dr = my_cm.ExecuteReader
dr.read()
dim a3 as string=dr("id").ToString
dr.close
strcon = "select id from tb where b1 like b2"
my_cm.CommandText = strcon
my_cm.Connection = my_cn
dr = my_cm.ExecuteReader
dr.read()
dim b3 as string=dr("id").ToString
dr.close
my_cm = Nothing
my_cn.Close()
my_cn = Nothing
EndSub
PrivateSub Button2_Click(sender AsObject, e As EventArgs) Handles Button2.Click
Dim my_cn AsNew SqlConnection
Dim my_cm AsNew SqlCommand
Dim dr As SqlDataReader
Dim path AsString
Dim strcon AsString
path = "server=(local);database=mydatabase;integrated security=false;" _
& "Persist Security Info=true;User ID=----;Password=-----"
my_cn.ConnectionString = path
my_cn.Open()
my_cn.ConnectionString = path
my_cn.Open()
strcon = "select id from tb2 where a1 like a2"
my_cm.CommandText = strcon
my_cm.Connection = my_cn
dr = my_cm.ExecuteReader
dr.read()
dim c3 as string=dr("id").ToString
dr.close
strcon = "select id from tb2 where b1 like b2"
my_cm.CommandText = strcon
my_cm.Connection = my_cn
dr = my_cm.ExecuteReader
dr.read()
dim d3 as string=dr("id").ToString
dr.close
my_cm = Nothing
my_cn.Close()
my_cn = Nothing
EndSub
end class