Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# re-using SQLCommand

Tags:

c#

sql

How do I reuse a SQLCommand for say multiple queries?

e.g

SqlCommand mycommand = new SqlCommand("SElect * from BKLAH", myConnection);
mycommand.ExecuteNonQuery();

Now I want to use mycommand again but use a different SQL query. How would I do this?

like image 227
user1158745 Avatar asked Jan 14 '23 16:01

user1158745


1 Answers

You can set CommandText property of your command, like this:

mycommand.CommandText = @"UPDATE BKLAH SET a = 5 WHERE id=@id";
like image 75
Sergey Kalinichenko Avatar answered Jan 25 '23 23:01

Sergey Kalinichenko