简体   繁体   English

将数据库SQL Server 2008链接到Visual Studio 2010

[英]Linked database sql server 2008 to visual studio 2010

I'm doing a software which can manage electronics component quantity. 我正在做一个可以管理电子元件数量的软件。 My software is linked to a first DB (T_importReel) that will have all the new reels component when the factory receive them. 我的软件链接到第一个数据库(T_importReel),当工厂收到它们时,它将具有所有新的卷轴组件。 The machine that uses component is counting how many it has used in each reels and marks the count in its own DB (SiplaceSetupCenter). 使用组件的机器将计算每个卷轴中已使用的数量,并在其自己的数据库(SiplaceSetupCenter)中标记该计数。 I'm using an Unique ID for each reel so T_importReel and SiplaceSetupCenter are using that Unique ID to differentiate each bobine. 我为每个卷轴使用唯一ID,因此T_importReel和SiplaceSetupCenter使用该唯一ID来区分每个线轴。 Basically, I have in the two DB two columns that are the same. 基本上,我在两个数据库中有两个相同的列。

Now I would like to link the two DB with a simple SQL request. 现在,我想用一个简单的SQL请求链接两个数据库。 This is supposed to be simple : for every Unique ID where the quantity is different between the two DB, T_importReel changes its quantity for the Unique ID concerned. 这应该很简单:对于两个DB之间数量不同的每个唯一ID,T_importReel会为有关唯一ID更改其数量。

But when I've tried to do so, my soft didn't access DB_center... How can I enable my soft to access SetUpCenter? 但是,当我尝试这样做时,我的软件无法访问DB_center ...如何使我的软件能够访问SetUpCenter? What do I do to update T_importreels? 我该怎么做才能更新T_importreels? Thank you in advance. 先感谢您。

 private void BT_croiserlesdonnées_Click(object sender, EventArgs e)
  {

     SqlConnection con = new SqlConnection("Server=SIPLACESERVER;Database=SiplaceSetupCenter;User=**;Password=****;");
      con.Open();
      // using (SqlCommand command = new SqlCommand(
      //      "SELECT packagingunitid,Quantity FROM PackagingUnit",
      //      con))
      //using (SqlDataReader reader = command.ExecuteReader())
      //      {
      //          while (reader.Read())
      //          {
      //              for (int i = 0; i < reader.FieldCount; i++)
      //              {
      //                  Console.WriteLine(reader.GetValue(i));
      //              }
      //              Console.WriteLine();
      //          }
      //      }

     string queryString = 
          "Select Quantity FROM PackagingUnit, T_ImportReels WHERE PackagingUnit.id = T_ImportReels.id";
      SqlCommand command = new SqlCommand(
        queryString, con);

    SqlDataReader reader = command.ExecuteReader();
    try
    {
        while (reader.Read())
        {
            Console.WriteLine(String.Format("{0}, {1}",
                reader[0], reader[1]));
        }
    }
    finally
    {
        // Always call Close when done reading.
        reader.Close();
    }

      //_siplaceSetupCenter = new SiplaceSetupCenterEntities();
      //string queryString = @"SELECT * FROM PackagingUnit";

      //using (SiplaceSetupCenterEntities context = new SiplaceSetupCenterEntities())
      //{


      //    //ObjectQuery<PackagingUnit> contactQuery =_siplaceSetupCenter.CreateQuery<PackagingUnit>(queryString);
      //    // new ObjectParameter("fn", "Frances"));
      //    Console.WriteLine("on y go"); Console.WriteLine("on y go"); Console.WriteLine("on y go"); Console.WriteLine("on y go");
      //    var tableresult = _siplaceSetupCenter.PackagingUnit.FirstOrDefault(id => id.PackagingUnitId == "100717132736");



          //var contactQuery = from contact in context.PackagingUnit
          //                   where contact.PackagingUnitId == "200717100643"
          //                   select contact;
          //// Iterate through the collection of Contact items.
          //foreach (PackagingUnit result in contactQuery)
          //    Console.WriteLine("First Name: {0}, Last Name: {1}",result.PackagingUnitId, result.Quantity);
          //Console.WriteLine(table_result.Count); Console.WriteLine(table_result.Count); Console.WriteLine(table_result.Count); Console.WriteLine(table_result.Count);
          //foreach (var value in table_result)
          //{
          //    Console.WriteLine(value); Console.WriteLine(value); Console.WriteLine(value); Console.WriteLine(value);
          //    Console.WriteLine("a"); Console.WriteLine("a"); Console.WriteLine("a"); Console.WriteLine("a");
          //}

          //string dataid = tableresult.PackagingUnitId;
          //Console.WriteLine(dataid);
      }
  }

I 一世

I don't know how it could help you? 我不知道它对您有什么帮助? You can make two connections that each one connects to each database then select your Data from two Db. 您可以建立两个连接,每个连接到每个数据库,然后从两个Db中选择数据。 In this situation you have 2 DataTable/ SqlDataReader objects. 在这种情况下,您有2个DataTable / SqlDataReader对象。 Now You can compare these Datatables/SqlDataReader row by row with each others or combine them into a single datatable/SqlDataReader or update each one base another. 现在,您可以将这些Datatables / SqlDataReader逐行进行比较,或者将它们组合为一个datatable / SqlDataReader或彼此更新。

Sql Server's name should be sth like this SERVERNAME\\INSTANCENAME. Sql Server的名称应类似于此SERVERNAME \\ INSTANCENAME。 But your server name is this: SIPLACESERVER/SIPLACE_2012EX. 但是您的服务器名称是:SIPLACESERVER / SIPLACE_2012EX。

If you use "\\" character in your server name, in connection string change it into "\\\\". 如果在服务器名称中使用“ \\”字符,请在连接字符串中将其更改为“ \\\\”。 i mean change SERVERNAME\\INSTANCENAME into SERVERNAME\\\\INSTANCENAME . 我的意思是将SERVERNAME\\INSTANCENAME更改为SERVERNAME\\\\INSTANCENAME

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将SQL Server 2008 R2数据库添加到Visual Studio 2010安装文件中? - How to add my SQL Server 2008 R2 database to my Visual Studio 2010 Setup File? 通过Visual Studio 2010 C#访问sql 2008数据库 - Accessing sql 2008 database through visual studio 2010 C# 在Visual Studio 2010上连接到远程SQL Server 2008 - Connect to remote SQL Server 2008 on Visual Studio 2010 将数据库移至新服务器后,无法在Visual Studio 2010的实体框架设计器中看到SQL Server 2008表 - Unable to see SQL Server 2008 tables within entity framework designer of visual studio 2010 after moving database to new server 在 Visual Studio 2008 中连接到 SQL Server 2012 数据库 - Connecting to a SQL Server 2012 database in Visual Studio 2008 检索存储在Visual Studio 2010中的SQL Server CE数据库中的信息 - Retrieving information stored in a SQL Server CE database in Visual Studio 2010 使用Visual Studio Express 2010(甚至2008)设置嵌入式SQL Server? - Embedded SQL server setup up with Visual Studio Express 2010 (or even 2008)? SQL Server关系中一个非常有趣的问题(SQL Server 2008R2,LINQ To SQL,Visual Studio 2010,C#) - A very interesting problem with SQL Server Relationships (SQL Server 2008R2, LINQ To SQL, Visual Studio 2010, C#) 如何在Visual Studio 2010 / SSMS 2008中使用生成的数据填充数据库? - How to populate database with generated data in visual studio 2010 / SSMS 2008? SQL Server 2008和Visual Studio 2012 - SQL Server 2008 and Visual Studio 2012
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM