[英]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.