我该如何编写此代码?
int ID;
ID = int.Parse(med_ID.Text);
using (SqlConnection conn = new SqlConnection(@"Data Source=DESKTOP-HCLRURF\SQLEXPRESS;Initial Catalog=ydb;Integrated Security=True"))
{
using (SqlCommand cmd = new SqlCommand("SELECT Quantite FROM TabRestitue WHERE Tab_medID= @medId ORDER BY DateDePeremption ASC "))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@medId", "%" + ID + "%");
conn.Open();
cmd.Connection = conn;
DataSet dt = new DataSet();
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(dt);
}
dgrAffich_tab.DataSource = dt;
conn.Close();
}
}
这段代码$sorgu=$dbpdo->query("SELECT * FROM denetci_mahalle");
for ($i=0; $sorgu->rowCount(); $i++)
{
$isletme=$dbpdo->prepare("
UPDATE isletmeler
JOIN denetci_mahalle
ON isletmeler.adresi like '%'+@denetci_mahalle.mahalle+'%'
SET isletmeler.sorumlu = denetci_mahalle.denetci
");
$isletme->execute();
}
是真的吗?请帮助我。
答案 0 :(得分:0)
+
不适用于PHP中的连接字符串,如果您需要可以使用。或者更好的连续..而且你决定使用@ denetci_mahalle.mahall你不能分配
你应该使用$ sorgu的结果
$sorgu=$dbpdo->query("SELECT * FROM denetci_mahalle");
foreach ($sorgu as $row) {
$isletme=$dbpdo->prepare("
UPDATE isletmeler
JOIN denetci_mahalle
ON isletmeler.adresi like concat('%','" . $row['mahalle'] . "','%')
SET isletmeler.sorumlu = denetci_mahalle.denetci
");
$isletme->execute();
}
无论如何你可以避免使用
的foreach $isletme=$dbpdo->prepare("
UPDATE isletmeler a
JOIN denetci_mahalle b
ON a.adresi like concat('%', b.mahalle ,'%')
SET a.sorumlu = b.denetci
");
$isletme->execute();
答案 1 :(得分:0)
不需要游标和循环。您可以在一个查询中执行此操作:
UPDATE isletmeler i JOIN
denetci_mahalle m
ON i.adresi like concat('%', d.mahalle, '%')
SET i.sorumlu = d.denetci;
不需要外部选择。