【问题标题】:Connection to CRM Sql Server连接到 CRM Sql 服务器
【发布时间】:2013-09-15 03:32:07
【问题描述】:

我正在尝试从 Visual Studio 中的 C# 项目连接到 CRM SQL 服务器。

我已经将数据库添加为数据连接,但我不知道如何在代码中连接到它以及如何进行示例查询(例如SELECT * FROM FilteredAccount

有什么建议吗?

【问题讨论】:

  • 这是一个非常基础的问题,我建议研究和学习 ADO.NET 的基础知识。

标签: c# sql sql-server visual-studio dynamics-crm-2011


【解决方案1】:

如果您想连接到本地 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():

   }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多