ma ouml

ma ouml

  • NA
  • 436
  • 88.9k

How to edit and delete in sql server

May 1 2017 6:29 PM
Hi friends
I will post another old publication
I hope I find someone who can help me
This is my problem
I have a problem is that I had a table named authorisation in this structure
create table autorisation
(
Id_autorisation int primary key identity NOT NULL,
Id_user int foreign key references utilisateur (Id_user),
Id_site int foreign key references site (Id_site),
Id_profil int foreign key references profil (Id_profil)
)
In visual studio I have this interface
 
update ===>
Program.cmd.CommandText="update autorisation set Id_site = (select top 1 Id_site from site where Libelle_site = '"+comboBox2.Text+"') , Id_user = (select top 1 Id_user from utilisateur where User_name = '"+comboBox1.Text+"') , Id_profil = (select top 1 Id_profil from profil where Libelle_profil = '"+comboBox3.Text+"') where Id_user = (select top 1 Id_user from utilisateur where User_name = @par1)";
Program.cmd.Parametrers.AddWithValue("@par1",comboBox1.Text);
Program.cmd.ExecuteNonQuery();
delete ====>
Program.cmd.CommandText = "delete from autorisation where Id_user = (select top 1 Id_user from utilisateur where User_name = @par2)";
Program.cmd.Parametrers.AddWithValue("@par2",comboBox1.Text);
Program.cmd.ExecuteNonQuery();
 
How to modify and delete without specifying in the where clause the id of the current table 
 Is there is another method for editing and deleting without working with Id_autorisation
thanks for advance 

Answers (4)