我從第一數據庫由用戶選擇門票的第一列表和我從另一個數據庫 我想這兩個名單對比第二列表進行比較,以數據的列表,如果車票的標識是一樣的! 但我認爲在我的代碼中有什麼問題,任何人都可以幫助我嗎? the result is here in this picture從兩個數據庫
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
**strong text**
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\iharbahoui\Desktop\ConsoleApplication1\ConsoleApplication1\glpi.mdf;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("select * from glpi_tickets where user_id_recipient =1", con);
DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dt);
if (dt.Rows.Count >0)
{
//créér une planification du ticket dans l'agenda de la ressource
SqlConnection cnx = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\iharbahoui\Desktop\ConsoleApplication1\ConsoleApplication1\AZPbd.mdf;Integrated Security=True");
cnx.Open();
SqlCommand req1 = new SqlCommand("select * from planification where user_id =1",cnx);
DataTable tb = new DataTable();
SqlDataAdapter adpt = new SqlDataAdapter(req1);
adpt.Fill(tb);
foreach (DataRow row1 in dt.Rows)
{
foreach(DataRow row2 in tb.Rows)
{
if (row1["Id"].Equals(row2["idTicket"]))
{
Console.WriteLine("ticket existe deja");
}
else
{
Console.WriteLine("ticket n'existe");
}
}
}
}
else
{
Console.WriteLine("Ticket n'existe pas");
}
con.Close();
Console.ReadLine();
}
}
}
究竟你認爲是錯的?它似乎沒有崩潰。別忘了我們無法看到您的源數據。你是說它不會產生預期的結果?如果是這樣,你需要提供你期望的結果和一個數據樣本,然後任何人都可以實際發現問題。 – ADyson
一步一步地調試你的代碼 - 在這種類型的循環中有這個消息是正常的。 – Aristos