Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all, I am a beginner c# developer. I have a sql query.
SQL
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand("DELETE FROM ranks WHERE rank_id NOT IN (SELECT DISTINCT(rank_id) FROM rank_transaction_type) AND rank_id = @rank_id",con);

How can you check if the delete query was successful and use it in 'if' statement. And store in variable.

for example:

if (queryworked == true)
{
}
else
{
}

Any help would be much appreciated. Thanking you in advance.
Posted

1 solution

When you execute your query (for e.g. using the ExecuteNonQuery method[^]) has a return type that indicates the number of rows affected. You can use this value

E.g.
C#
int rowsAffected = cmd.ExecuteNonQuery();
if (rowsAffected >0)
{
}
else
{
}
 
Share this answer
 
v3
Comments
Ruwaldo 12-Jul-12 9:53am    
Thank you this is exactly what i was looking for.
Abhinav S 12-Jul-12 10:00am    
You are welcome.

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