Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ADO.NET Table Columns Names
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