Skip to content
Advertisement

Execute query using C# [closed]

I am trying to execute some SQL code, connected directly to my database, but I don’t know how to execute the query.

Advertisement

Answer

SqlCommand has ExecuteReader, for executing the command and returning a dataset, ExecuteScalar for returning a single value of a primitive type (int, string, etc.), or executeNonQuery for returning nothing. You can also pass a command to a SqlDataAdapter, and use that to populate a DataTable object.

Please google SqlCommand and you will find LOTS of examples.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement