10-04-20, 07:36 PM
(10-04-20, 04:10 PM)سعود كتب : [ -> ]جربت كود ونجح معي ومسالة الامور الاخرى لا اعلم عنها واقصد ماتحدث به الاخوة لاني عملت جداول جديدة وحذفتها بالكود مرة واحدة
اولا ضع مربع نص لتضع به جملة الاتصال كاملة وليكن اسمها TextBox1
اكتب الدالة التالية:
PHP كود :
Function drop(str As String, tt As String) As String
Using con As New SqlClient.SqlConnection(str)
Using cm As New SqlClient.SqlCommand("", con)
cm.CommandText = "DROP TABLE " & tt & ""
If con.State = ConnectionState.Closed Then con.Open()
Try
cm.ExecuteNonQuery()
Return "Droped... " & tt & " "
Catch ex As Exception
Return Err.Description
End Try
If con.State = ConnectionState.Open Then con.Close()
End Using
End Using
End Function
النقطة الاهم واللتي تبحث عنها على مااظن هي بالكود التالي:
ارجو تعطيني خبر اذا هذه الاكواد عملت عندك.PHP كود :
Using con As New SqlClient.SqlConnection(TextBox1.Text)
'SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
Using cm As New SqlClient.SqlCommand("", con)
cm.CommandText = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES"
If con.State = ConnectionState.Closed Then con.Open()
Dim dr As SqlClient.SqlDataReader = cm.ExecuteReader
Do While dr.Read
MsgBox(drop(TextBox1.Text, dr(0).ToString))
Loop
dr.Close()
If con.State = ConnectionState.Open Then con.Close()
End Using
End Using
تنبيه!
تحتاج تمرير هذه الجملة بكود الاتصال:
وهي لتمكين تعدد مهام القاريء(حسب تعبيري وفهمي)PHP كود :
MultipleActiveResultSets=True;
الف شكر اخي سعود علي اهتمامك ومساعدتك لي
بصراحه مبدع والله بارك الله فيك وجعله الله في ميزان حسناتك ان شاء الله
الكود اشتغل كويس خالص
وحدف كل الجداول فيماعدا الاستعلامات فقمت بتعديل بسيط جدا علي الكود بتاعك فتم حدف الجداول والاستعلامات
مع العلم اني لم استخدم هده الجمله لاني معرفتش احطها فين
وهدا هو الكود ارجو مراجعته فربما يكون به خطا لم يظهر معي حتي يستفيد به الجميعPHP كود :
MultipleActiveResultSets=True
PHP كود :
Function drop_Tables(str As String, tt As String) As String
Using con As New SqlConnection(str)
Using cm As New SqlCommand("", con)
cm.CommandText = "DROP TABLE " & tt & ""
If con.State = ConnectionState.Closed Then con.Open()
Try
cm.ExecuteNonQuery()
Return "Droped... " & tt & " "
Catch ex As Exception
Return Err.Description
End Try
If con.State = ConnectionState.Open Then con.Close()
End Using
End Using
End Function
Function drop_Views(str As String, tt As String) As String
Using con As New SqlConnection(str)
Using cm As New SqlCommand("", con)
cm.CommandText = "DROP View " & tt & ""
If con.State = ConnectionState.Closed Then con.Open()
Try
cm.ExecuteNonQuery()
Return "Droped... " & tt & " "
Catch ex As Exception
Return Err.Description
End Try
If con.State = ConnectionState.Open Then con.Close()
End Using
End Using
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'كود حدف جميع الجداول من قاعدة البيانات
Using con As New SqlConnection(TextBox1.Text)
Using cm As New SqlClient.SqlCommand("", con)
cm.CommandText = "SELECT Table_NAME FROM INFORMATION_SCHEMA.TABLES"
If con.State = ConnectionState.Closed Then con.Open()
Dim dr As SqlClient.SqlDataReader = cm.ExecuteReader
Do While dr.Read
drop_Tables(TextBox1.Text, dr(0).ToString)
Loop
dr.Close()
If con.State = ConnectionState.Open Then con.Close()
End Using
End Using
Using con As New SqlConnection(TextBox1.Text)
Using cm As New SqlClient.SqlCommand("", con)
cm.CommandText = "SELECT Table_NAME FROM INFORMATION_SCHEMA.Views"
If con.State = ConnectionState.Closed Then con.Open()
Dim dr As SqlClient.SqlDataReader = cm.ExecuteReader
Do While dr.Read
drop_Views(TextBox1.Text, dr(0).ToString)
Loop
dr.Close()
If con.State = ConnectionState.Open Then con.Close()
End Using
End Using
End Sub
وبارك الله فيك اخي مره اخري