【发布时间】:2014-05-08 14:45:14
【问题描述】:
我的数据库中有 2 个表(Echipa 和 Staff)与关系相关联。
要在我的表格中添加一行,我只需在第一个中添加,然后在第二个中添加
private void AddElement(string nume, string an, string tara, string antrenor, string presedinte, string actionar)
{
conexiune.Open();
Comanda comanda = new Comanda("insert into echipa values( @nume, @an,@tara)", conexiune);
comanda.Parameters.Add(new SqlParameter("@nume", nume));
comanda.Parameters.Add(new SqlParameter("@an", an));
comanda.Parameters.Add(new SqlParameter("@tara", tara));
comanda.ExecuteNonQuery();
comanda = new Comanda("insert into staff values( @antrenor,@presedinte,@actionar)", conexiune);
comanda.Parameters.Add(new SqlParameter("@antrenor", antrenor));
comanda.Parameters.Add(new SqlParameter("@presedinte", presedinte));
comanda.Parameters.Add(new SqlParameter("@actionar", actionar));
comanda.ExecuteNonQuery();
conexiune.Close();
MessageBox.Show("Succes");
}
但是如果我想删除一行来更新一行呢? 我该怎么办?
我不知道为什么,但我什至无法从 1 个表中删除
private void DeleteElement(string nume)
{
conexiune.Open();
Comanda comanda = new Comanda("delete from echipa where 'nume'=@nume", conexiune);
comanda.Parameters.Add(new SqlParameter("@nume", nume));
comanda.ExecuteNonQuery();
conexiune.Close();
MessageBox.Show("Succes");
}
这不会对我的桌子造成任何影响..
【问题讨论】:
标签: c# sql sql-server database