تعديل اتصال بيانات SQL الموجود باستخدام Aspose.Cells
Contents
[
Hide
]
يدعم Aspose.Cells تعديل وصلة بيانات SQL الموجودة. تشرح المقالة كيفية استخدام Aspose.Cells لتعديل الخصائص المختلفة لاتصال بيانات SQL.
يمكنك إضافة أو مشاهدة اتصالات البيانات داخل Microsoft Excel باتباع الخطوات التاليةالبيانات> الاتصالات أمر القائمة.
وبالمثل ، يوفر Aspose.Cells الوسائل للوصول إلى اتصالات البيانات وتعديلها باستخدام مجموعة Workbook.DataConnections.
تعديل اتصال بيانات SQL الموجود باستخدام Aspose.Cells
يوضح النموذج التالي استخدام Aspose.Cells لتعديل اتصال بيانات SQL للمصنف. يمكنك تنزيل ملف Excel المصدر المستخدم في هذا الرمز وملف Excel الناتج الذي تم إنشاؤه بواسطة الكود من الروابط التالية.
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 workbook object | |
Workbook workbook = new Workbook(dataDir + "DataConnection.xlsx"); | |
// Access first Data Connection | |
ExternalConnection conn = workbook.DataConnections[0]; | |
// Change the Data Connection Name and Odc file | |
conn.Name = "MyConnectionName"; | |
conn.OdcFile = "C:\\Users\\MyDefaulConnection.odc"; | |
// Change the Command Type, Command and Connection String | |
DBConnection dbConn = conn as DBConnection; | |
dbConn.CommandType = OLEDBCommandType.SqlStatement; | |
dbConn.Command = "Select * from AdminTable"; | |
dbConn.ConnectionString = "Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False"; | |
// Save the workbook | |
workbook.Save(dataDir + "output_out.xlsx"); |