Click here to Skip to main content
16,021,580 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi my friends.
i have this code in c#.
but i have error for query:

C#
SqlCommand cmd1 = new SqlCommand();                
 cmd1.Connection = Class_SQL.con;

                cmd1.CommandText = "delete from Tbl_CustomerTools where IDDevice=(select ID from Tbl_CustomerDevice where Cust_Id=(select Cust_Id from Tbl_CustomerDetail where Cust_Id = '" + IDCust_Selected + "))'";
                
                Class_SQL.con.Open();
                cmd1.ExecuteNonQuery();
                Class_SQL.con.Close();



and i test this query in sql and it was true.
but in c# no.
what should i do??

What I have tried:

SqlCommand cmd1 = new SqlCommand();
cmd1.Connection = Class_SQL.con;

cmd1.CommandText = "delete from Tbl_CustomerTools where IDDevice=(select ID from Tbl_CustomerDevice where Cust_Id=(select Cust_Id from Tbl_CustomerDetail where Cust_Id = '" + IDCust_Selected + "))'";

Class_SQL.con.Open();
cmd1.ExecuteNonQuery();
Class_SQL.con.Close()
Posted
Updated 17-Aug-16 0:51am

ook. i solved it. this code is true :

C#
cmd1.CommandText = "delete from Tbl_CustomerTools where IDDevice in (select ID from Tbl_CustomerDevice where Cust_Id in (select Cust_Id from Tbl_CustomerDetail where Cust_Id = " + IDCust_Selected + "))";
 
Share this answer
 
you should be assigned CommandType:

C#
cmd1.CommandType=CommandType.Text
 
Share this answer
 
In
C#
cmd1.CommandText = "delete from Tbl_CustomerTools where IDDevice=(select ID from Tbl_CustomerDevice where Cust_Id=(select Cust_Id from Tbl_CustomerDetail where Cust_Id = '" + IDCust_Selected + "))'";

you should try to replace "))'" with "'))"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900