استرداد بيانات اتصال SQL
Contents
[
Hide
]
يمكن أن يساعدك Aspose.Cells في استرداد بيانات اتصال SQL. يتضمن ذلك أي وكافة البيانات المطلوبة لإجراء اتصال بخادم SQL ، على سبيل المثال ،URL الخادم, اسم االمستخدم, اسم الطاولة, استعلام SQL كامل, نوع الاستعلام, موقع الجدول ، واسم النطاق المسمى المرتبطة بها.
في Microsoft Excel ، اتصل بقاعدة بيانات عن طريق:
- النقر فوق ملفبيانات القائمة والاختيارمن مصادر أخرى تليهامن SQL Server.
- ثم حددبيانات تليهاروابط.
- استخدم معالج الاتصالات للاتصال بقاعدة البيانات وإنشاء استعلام قاعدة بيانات.
يوفر Aspose.Cells الخاصية Workbook.DataConnections لاسترجاع الوصلات الخارجية. تقوم بإرجاع مجموعة من كائنات ExternalConnection في المصنف.
إذا كان كائن ExternalConnection يحتوي على بيانات اتصال SQL ، فيمكن أن يكون نوع لصق لكائن DBConnection ويمكن استخدام خصائصه لاسترداد أمر قاعدة البيانات ونوع الأمر ووصف الاتصال ومعلومات الاتصال وبيانات الاعتماد وما إلى ذلك.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook object from source file | |
Workbook workbook = new Workbook(dataDir+ "connection.xlsx"); | |
// Access the external collections | |
ExternalConnectionCollection connections = workbook.DataConnections; | |
int connectionCount = connections.Count; | |
ExternalConnection connection = null; | |
for (int i = 0; i < connectionCount; i++) | |
{ | |
connection = connections[i]; | |
// Check if the Connection is DBConnection, then retrieve its various properties | |
if (connection is DBConnection) | |
{ | |
DBConnection dbConn = (DBConnection)connection; | |
// Retrieve DB Connection Command | |
Console.WriteLine("Command: " + dbConn.Command); | |
// Retrieve DB Connection Command Type | |
Console.WriteLine("Command Type: " + dbConn.CommandType); | |
// Retrieve DB Connection Description | |
Console.WriteLine("Description: " + dbConn.ConnectionDescription); | |
// Retrieve DB Connection ID | |
Console.WriteLine("Id: " + dbConn.Id); | |
// Retrieve DB Connection Info | |
Console.WriteLine("Info: " + dbConn.ConnectionString); | |
// Retrieve DB Connection Credentials | |
Console.WriteLine("Credentials: " + dbConn.CredentialsMethodType); | |
// Retrieve DB Connection Name | |
Console.WriteLine("Name: " + dbConn.Name); | |
// Retrieve DB Connection ODC File | |
Console.WriteLine("OdcFile: " + dbConn.OdcFile); | |
// Retrieve DB Connection Source File | |
Console.WriteLine("Source file: " + dbConn.SourceFile); | |
// Retrieve DB Connection Type | |
Console.WriteLine("Type: " + dbConn.SourceType); | |
// Retrieve DB Connection Parameters Collection | |
ConnectionParameterCollection paramCollection = dbConn.Parameters; | |
int paramCount = paramCollection.Count; | |
// Iterate the Parameter Collection | |
for (int j = 0; j < paramCount; j++) | |
{ | |
ConnectionParameter param = paramCollection[j]; | |
// Retrieve Parameter Cell Reference | |
Console.WriteLine("Cell reference: " + param.CellReference); | |
// Retrieve Parameter Name | |
Console.WriteLine("Parameter name: " + param.Name); | |
// Retrieve Parameter Prompt | |
Console.WriteLine("Prompt: " + param.Prompt); | |
// Retrieve Parameter SQL Type | |
Console.WriteLine("SQL Type: " + param.SqlType); | |
// Retrieve Parameter Type | |
Console.WriteLine("Param Type: " + param.Type); | |
// Retrieve Parameter Value | |
Console.WriteLine("Param Value: " + param.Value); | |
}// End for | |
}// End if | |
}// End for |