اذهب الي المحتوي
أوفيسنا
بحث مخصص من جوجل فى أوفيسنا
Custom Search

كيف يتم ربط قاعدة SQL بشاشات ونماذج أكسس؟ (معدل)


الردود الموصى بها

السلام عليكم ورحمة الله و بركاته

كيفية ربط و ادخال و تعديل و حذف البيانات فى sql (قاعادة بيانات ) و الاكسيس ( نماذج و تقارير و شاشات بحث فقط )  بالاكواد

تم تعديل بواسطه ابو فتحى
رابط هذا التعليق
شارك

اخى الكريم  هل انت تمتلك قاعدة بيانات sql على استضافة فى سيرفير ما ؟؟

واذا كنت ذلك

هل تريد ربط الجداول من خلال النماذج ؟؟ فقط

ام تريد ربط الجداول من خلال الاكسس نفسه ؟؟

رابط هذا التعليق
شارك

اخى الكريم 

اولا " ممكن جدوال sql فى الكمبيوترالرئيسى  على الشبكة  او على موقع على النت 

ثانيا " تخزين البيانات عند زر الحفظ يتم عمل اتصال بقاعدة البيانات يتم اضافة البيانات او تعديله او حذفه ثم فصل الاتصال 

كل ذلك بالكود 

رابط هذا التعليق
شارك

اخى الكريم بالنسبة لانشاء الاتصال له طريقتين

الاولى

بالنسبة لموضوع الربط كانت الفكرة انك لو نقلت قاعدة البيانات بتاعتك لاكثر من جهاز هتضر تضيف اتصال DSN لكل جهاز عله قاعدة البيانات علشان تقدر تتصل بالداتابيز اللى على الاستضافة

الحل هو انك تنشء اتصال عن طريق وحدة نمطية بدون استخدام معالج البيانات فى الويندوز

اولا هتضيف الوحدة النمطية دى بدون التعدل عليها

'//Name     :   AttachDSNLessTable
'//Purpose  :   Create a linked table to SQL Server without using a DSN
'//Parameters
'//     stLocalTableName: Name of the table that you are creating in the current database
'//     stRemoteTableName: Name of the table that you are linking to on the SQL Server database
'//     stServer: Name of the SQL Server that you are linking to
'//     stDatabase: Name of the SQL Server database that you are linking to
'//     stUsername: Name of the SQL Server user who can connect to SQL Server, leave blank to use a Trusted Connection
'//     stPassword: SQL Server user password
Function AttachDSNLessTable(stLocalTableName As String, stRemoteTableName As String, stServer As String, stDatabase As String, Optional stUsername As String, Optional stPassword As String)
    On Error GoTo AttachDSNLessTable_Err
    Dim td As TableDef
    Dim stConnect As String
    
    For Each td In CurrentDb.TableDefs
        If td.Name = stLocalTableName Then
            CurrentDb.TableDefs.Delete stLocalTableName
        End If
    Next
      
    If Len(stUsername) = 0 Then
        '//Use trusted authentication if stUsername is not supplied.
        stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";Trusted_Connection=Yes"
    Else
        '//WARNING: This will save the username and the password with the linked table information.
        stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";UID=" & stUsername & ";PWD=" & stPassword
    End If
    Set td = CurrentDb.CreateTableDef(stLocalTableName, dbAttachSavePWD, stRemoteTableName, stConnect)
    CurrentDb.TableDefs.Append td
    AttachDSNLessTable = True
    Exit Function

AttachDSNLessTable_Err:
    
    AttachDSNLessTable = False
    MsgBox "AttachDSNLessTable encountered an unexpected error: " & Err.Description

End Function

وفى حدث عند فتح النموذج ستضيف الكود التالى
 

Private Sub Form_Open(Cancel As Integer)
    If CreateDSNConnection("(اسم السرفر )", "اسم قاعدة البيانات ", "اسم المستخدم ", "كلمة السر ") Then
        '// All is okay.
    Else
        '// Not okay.
    End If
End Sub

ودى اول طريقة

  • Like 1
رابط هذا التعليق
شارك

الحل الثانى  وهو ربط القاعدة مباشرة بالجدوال الموجودة على قاعدة SQL

عن طريق الوحدة النمطية دى

'//Name     :   AttachDSNLessTable
'//Purpose  :   Create a linked table to SQL Server without using a DSN
'//Parameters
'//     stLocalTableName: Name of the table that you are creating in the current database
'//     stRemoteTableName: Name of the table that you are linking to on the SQL Server database
'//     stServer: Name of the SQL Server that you are linking to
'//     stDatabase: Name of the SQL Server database that you are linking to
'//     stUsername: Name of the SQL Server user who can connect to SQL Server, leave blank to use a Trusted Connection
'//     stPassword: SQL Server user password
Function AttachDSNLessTable(stLocalTableName As String, stRemoteTableName As String, stServer As String, stDatabase As String, Optional stUsername As String, Optional stPassword As String)
    On Error GoTo AttachDSNLessTable_Err
    Dim td As TableDef
    Dim stConnect As String
    
    For Each td In CurrentDb.TableDefs
        If td.Name = stLocalTableName Then
            CurrentDb.TableDefs.Delete stLocalTableName
        End If
    Next
      
    If Len(stUsername) = 0 Then
        '//Use trusted authentication if stUsername is not supplied.
        stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";Trusted_Connection=Yes"
    Else
        '//WARNING: This will save the username and the password with the linked table information.
        stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";UID=" & stUsername & ";PWD=" & stPassword
    End If
    Set td = CurrentDb.CreateTableDef(stLocalTableName, dbAttachSavePWD, stRemoteTableName, stConnect)
    CurrentDb.TableDefs.Append td
    AttachDSNLessTable = True
    Exit Function

AttachDSNLessTable_Err:
    
    AttachDSNLessTable = False
    MsgBox "AttachDSNLessTable encountered an unexpected error: " & Err.Description

End Function

وفى حدث عند الفتح للنموذج

Private Sub Form_Open(Cancel As Integer)
    If AttachDSNLessTable("authors", "authors", "(local)", "pubs", "", "") Then
        '// All is okay.
    Else
        '// Not okay.
    End If
End Sub

وشكر الله لك

رابط هذا التعليق
شارك

تعديل اخى الكريم فى الوحدة النمطية الاولى

الخاصة بانشاء اتصال DSN

 

وانا براجع الموضوع لقيت الوحدتين مثل بعض تماما

 

وهذه هى تصحيح الوحدة النمطية الاولى

'//Name     :   CreateDSNConnection
'//Purpose  :   Create a DSN to link tables to SQL Server
'//Parameters
'//     stServer: Name of SQL Server that you are linking to
'//     stDatabase: Name of the SQL Server database that you are linking to
'//     stUsername: Name of the SQL Server user who can connect to SQL Server, leave blank to use a Trusted Connection
'//     stPassword: SQL Server user password
Function CreateDSNConnection(stServer As String, stDatabase As String, Optional stUsername As String, Optional stPassword As String) As Boolean
    On Error GoTo CreateDSNConnection_Err

    Dim stConnect As String
    
    If Len(stUsername) = 0 Then
        '//Use trusted authentication if stUsername is not supplied.
        stConnect = "Description=myDSN" & vbCr & "SERVER=" & stServer & vbCr & "DATABASE=" & stDatabase & vbCr & "Trusted_Connection=Yes"
    Else
        stConnect = "Description=myDSN" & vbCr & "SERVER=" & stServer & vbCr & "DATABASE=" & stDatabase & vbCr 
    End If
    
    DBEngine.RegisterDatabase "myDSN", "SQL Server", True, stConnect
        
    '// Add error checking.
    CreateDSNConnection = True
    Exit Function
CreateDSNConnection_Err:
    
    CreateDSNConnection = False
    MsgBox "CreateDSNConnection encountered an unexpected error: " & Err.Description
    
End Function

ويمكنك مراجعة ذلك من خلال موقع الدعم فى ميكروسوفت

 

https://support.microsoft.com/en-us/kb/892490

رابط هذا التعليق
شارك

  • 2 weeks later...
  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

زائر
اضف رد علي هذا الموضوع....

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • تصفح هذا الموضوع مؤخراً   0 اعضاء متواجدين الان

    • لايوجد اعضاء مسجلون يتصفحون هذه الصفحه
×
×
  • اضف...

Important Information