SQL/C# - Best method for executing a query
问题 I need to execute a sql query from within a c# class. I have thought of 2 options Starting a process of sqlcmd. Using a SqlCommand object. My question is which would be the better way? It's important that the solution only holds a connection to the server for a short time. I'm open to other ideas if the above aren't good. Thanks in advance. 回答1: Use a SqlCommand. This code will only keep the connection alive for a very short period of time (as long as your query is performant): DataTable