Created
October 15, 2012 20:01
-
-
Save sergey-tihon/3894956 to your computer and use it in GitHub Desktop.
ADO.NET Table Columns Names
This file contains 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
namespace ADOConsoleApplication | |
{ | |
using System; | |
using System.Data; | |
using System.Data.SqlClient; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
const string ConnectionString = "Data Source=MYCOMPUTER\\SQLEXPRESS;Initial Catalog=DEMODB;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"; | |
using (var connection = new SqlConnection(ConnectionString)) | |
{ | |
const string Query = "SELECT * FROM dbo.Cases"; | |
var cmd = new SqlCommand(Query, connection); | |
var da = new SqlDataAdapter(cmd); | |
var ds = new DataSet(); | |
da.Fill(ds, "Cases"); | |
foreach (DataColumn dc in ds.Tables[0].Columns) | |
Console.WriteLine("{0,15}", dc.ColumnName); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment