To query a SQL database in C#, you can use the SqlConnection class to establish a connection to the database and the SqlCommand class to execute SQL statements.
Here is an example code snippet:
main.cs754 chars26 lines
This code establishes a connection to a database using a connection string, creates a SQL command to select data from a table, executes the command, and reads the results using a SqlDataReader. Finally, the connection and reader are closed.
gistlibby LogSnag