Created
July 20, 2017 13:46
-
-
Save AntMooreWebDev/f3da874fc57973775a3e9597c969856c to your computer and use it in GitHub Desktop.
How to execute a simple SQL query in C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using(SqlConnection conn = new SqlConnection(connString)) | |
| using(SqlCommand command = new SqlCommand(query, conn)) | |
| using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command)) | |
| dataAdapter.Fill(results); | |
| using (SqlConnection conn = new SqlConnection(connString)) | |
| { | |
| conn.open(); | |
| using (SqlCommand command = new SqlCommand(query, conn)) | |
| { | |
| SqlDataReader reader = command.ExecuteReader(); | |
| while (reader.read()) | |
| { | |
| // Do Stuff | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment