(06-07-21, 01:08 AM)خالد20 كتب : شكرا على ردك ولكن هناك مشكلة هناك تغييرات نضطر لعملها في قاعدة البيانات في النسخ المحدثة
هذه التغييرات هي انشاء جداول جديدة واكواد جديدة وتعدل على اكواد قديمة واضافة حقول اضافية لبعض الجداول
طيب بعيدا عن الاستيراد والتصدير
ليش ما تضيف اوتعدل في جدول في نفس القاعدة التي مع الزبون بالكود
تعمل له شرط اذا كان الجودل موجود لاتفعل شيء
واذا كان غير موجود اضفه
شي مقارب لهذا
كود :
Option Strict On
Option Explicit On
Imports System.Data.SqlClient
Public Class MyForm
Private Sub MyForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New SqlConnection() 'Creates a new connection object
Dim cmd As New SqlCommand() 'Creates a new command object
Dim exists As Byte = 0 'Creates a byte variable that will store the cmd return value
conn.ConnectionString = "Data Source=MyServer; " & _
"Initial Catalog=MyDatabase; " & _
"User Id=MyUserId; " & _
"Password=MyPassword"
cmd.CommandText = "SELECT COUNT(*) " & _
"FROM sys.objects " & _
"WHERE object_id = OBJECT_ID(N'[dbo].[TableName]') " & _
"AND type in (N'U')"
Try
conn.Open() 'Opens the connection
cmd.Connection = conn 'Instructs the cmd object to use conn as its connection when executing
exists = CByte(cmd.ExecuteScalar()) 'Use ExecuteScalar to return a single value, the count, and assign it to the exists variable
conn.Close()
Catch ex As SqlException
MessageBox.Show(ex.Message) 'Catch any SqlException and display it in a MessageBox
Catch ex As Exception
MessageBox.Show(ex.Message) 'Catch any ApplicationException and display it in a MessageBox
End Try
MyButton.Enabled = CBool(exists) 'Convert the exists variable to a boolean to determine whether the button should be enabled.
'Note that by assigning the exists variable a value of 0 earlier, if there is an error in connecting to the database, the value will
'remain 0, and the button will be disabled by default.
End Sub
End Class
