Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to design html table in c# ???
how to pass sql server table values into html format in wpf apllication


What I have tried:

private void PDFSave()
        {
            string CmdString = string.Empty;
            using (SqlCeConnection conn = new SqlCeConnection(DBConnection.GetConnString()))
            {
                //CmdString = "select log.Username,log.EmailID,log.SchoolName,lt.LoginDate,lt.LogoutDate,lt.Medium from Login as log,LoginTime as Lt where log.EmailID = lt.EmailID   ";


                SqlCeCommand cmd = new SqlCeCommand("select log.Username,log.EmailID,log.SchoolName,lt.LoginDate,lt.LogoutDate,lt.Medium from Login as log,LoginTime as Lt where log.EmailID = lt.EmailID   ",conn);
                conn.Open();
              
                SqlCeDataAdapter read = cmd.ExecuteReader();
                cmd.ExecuteNonQuery();
                DataTable dt = new DataTable("Login");
                read.Fill(dt);
                string result = "<table class='table table-striped top-buffer'"
                + "style='width:300px'>"
                + "<tr><th>UserName(KG)</th><th>SchoolName</th><th>Date();</th></tr>";

                if (read.HasRows)
                {
                    while (read.Read())
                    {
                        Id = read["Id"].ToString();
                        System.Diagnostics.Debug.WriteLine(Id);

                        Weight = read["Weight"].ToString();
                        System.Diagnostics.Debug.WriteLine(Weight);

                        Rep = read["Rep"].ToString();
                        System.Diagnostics.Debug.WriteLine(Rep);

                        result += "<tr><td>" + Weight + "</td>"
                               + "</tr><tr><td>" + Rep + "</td></tr>";
                    }
                }
                else
                {
                    Console.WriteLine("nothing");
                }
                read.Close();
Posted
Updated 13-Mar-19 0:32am
Comments
James Walsh Jr 7-Mar-19 8:51am    
What errors are you getting? If you're not getting errors how is the output differing from what you are expecting?

Quote:
how to design html table in c# ???
how to pass sql server table values into html format in wpf apllication


You don't need to export data into html format!

All you need to do is to use DataGrid[^] control, which is used to display tabular data.

For further details, please see:
DataGrid with row details - The complete WPF tutorial[^]
WPF DataGrid Practical Examples[^]
WPF Datagrid[^]
 
Share this answer
 
Check following post that explains how to create dynamic html table using C# with code sample,
CodeChef4U | Creating Dynamic HTML table using C#[^]
 
Share this answer
 
C#
string WriteTable(DataTable dt)
{
    StringBuilder sb = new StringBuilder();

    sb.Append(@"
<table>
<tr>
<th>No</th>
<th>Code</th>
<th>Name</th>
</tr>
");

    foreach(DataRow dr in dt.Rows)
    {
        sb.Append("<tr>");
        sb.AppendFormat("<td>{0}</td>", dr["no"]);
        sb.AppendFormat("<td>{0}</td>", dr["code"]);
        sb.AppendFormat("<td>{0}</td>", dr["name"]);
        sb.Append("</tr>");
    }


    sb.Append("</table>");

    return sb.ToString();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900