[英]Connection to CRM Sql Server
我正在嘗試從Visual Studio中的C#項目連接到CRM SQL服務器。
我已經將數據庫添加為數據連接,但是我不知道如何在代碼中連接到數據庫以及如何進行示例查詢(例如SELECT * FROM FilteredAccount
)
有什么建議嗎?
如果要連接到本地SQL Server Express,並連接到“ Northwind”數據庫,並從“客戶”表中讀取前5名客戶,則必須執行以下操作:
string connectionString = "server=(local)\SQLExpress;database=Northwind;integrated Security=SSPI;";
using(SqlConnection _con = new SqlConnection(connectionString))
{
string queryStatement = "SELECT TOP 5 * FROM dbo.Customers ORDER BY CustomerID";
using(SqlCommand _cmd = new SqlCommand(queryStatement, _con))
{
DataTable customerTable = new DataTable("Top5Customers");
SqlDataAdapter _dap = new SqlDataAdapter(_cmd);
_con.Open();
_dap.Fill(customerTable);
_con.Close():
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.