Created
March 30, 2015 13:22
-
-
Save SteveBate/90bd9b0aaf56edf85f65 to your computer and use it in GitHub Desktop.
Example of connecting to Sql Server using async, await and tasks
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
| async void Main() | |
| { | |
| var cnn = new SqlConnection("Data Source=ERPDBUAT;Initial Catalog=Enterprise_Misc; Integrated Security=true"); | |
| cnn.Open(); | |
| var cmd = new SqlCommand("SELECT * FROM ShopService.DivisionRules WHERE DivCode = 'MHL001'", cnn); | |
| await cmd.ExecuteReaderAsync().ContinueWith(async rdr => { | |
| await rdr.Result.ReadAsync().ContinueWith(ok => { | |
| rdr.Result.GetBoolean(rdr.Result.GetOrdinal("IsMobileEnabled")).Dump(); | |
| rdr.Result.GetBoolean(rdr.Result.GetOrdinal("IsWebEnabled")).Dump(); | |
| rdr.Result.GetBoolean(rdr.Result.GetOrdinal("IsManualAddressEnabled")).Dump(); | |
| rdr.Result.GetBoolean(rdr.Result.GetOrdinal("ShouldValidateCompanyNameField")).Dump(); | |
| }); | |
| }); | |
| "hello world".Dump(); //linqpad | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment