The column names with the source SQL tables

2 posts, 1 answers
  1. Patrik
    Patrik avatar
    6 posts
    Member since:
    May 2009

    Posted 07 Aug Link to this post

    Good day,
    Maybe I'm wrong read, but I never found the opportunity, how to name columns by the column names in the SQL table.
    SQL table I used as a source of data and need to exit in the first row contains the column names.

    The result should look like the attached image.

    Thank you for your help and example source code.


    public override List<Worksheet> GetSheets()
                var result = new List<Worksheet>();
                DataTable data = GetData();
                var sheet = new Worksheet();
                sheet.Name = "Srpen 2016";
                int rowIndex = 1;
                foreach (DataRow dataRow in data.Rows)
                    var row = new Row() { Index = rowIndex++ };
                    int columnIndex = 0;
                    foreach(DataColumn dataColumn in data.Columns)
                        if (dataColumn.ColumnName == "DochazkaID") continue;
                        string cellValue = dataRow[dataColumn.ColumnName].ToString();
                        var cell = new Cell() { Index = columnIndex++, Value = cellValue };
                return result;
            public DataTable GetData()
                using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
                    string query = "SELECT Dochazka.DochazkaID,Zamestnanci.Prijmeni,Zamestnanci.Jmeno,Zakazky.Zkratka,Dochazka.MesicID,Dochazka.Den1,Dochazka.Den2,Dochazka.Den3,Dochazka.Den4,Dochazka.Den5,Dochazka.Den6,Dochazka.Den7,Dochazka.Den8,Dochazka.Den9,Dochazka.Den10,Dochazka.Den11,Dochazka.Den12,Dochazka.Den13,Dochazka.Den14,Dochazka.Den15,Dochazka.Den16,Dochazka.Den17,Dochazka.Den18,Dochazka.Den19,Dochazka.Den20,Dochazka.Den21,Dochazka.Den22,Dochazka.Den23,Dochazka.Den24,Dochazka.Den25,Dochazka.Den26,Dochazka.Den27,Dochazka.Den28,Dochazka.Den29,Dochazka.Den30,Dochazka.Den31 FROM dbo.Dochazka INNER JOIN dbo.Zamestnanci ON Dochazka.ZamestnanecID = Zamestnanci.ZamestnanecID INNER JOIN dbo.Zakazky ON Dochazka.ZakazkaID = Zakazky.ZakazkaID WHERE Dochazka.MesicID = DATEPART(MONTH, GETDATE()) ORDER BY Zamestnanci.Prijmeni";
                    SqlCommand cmd = new SqlCommand(query, conn);
                    DataTable dt = new DataTable();
                    return dt;


  2. Answer
    Veselin Tsvetanov
    Veselin Tsvetanov avatar
    241 posts

    Posted 10 Aug Link to this post

    Hello Patrik,

    The following Documentation example does exactly what you need.

    Veselin Tsvetanov
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. DevCraft R3 2016 release webinar banner
Back to Top