Good day i created a table to be displayed on A adminlte template but it is not displaying the data from the database on the table
- namespace WebApplication4
- {
- public partial class transahis : System.Web.UI.Page
- {
- SqlDataAdapter da;
- DataSet ds = new DataSet();
- StringBuilder htmlTable = new StringBuilder();
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!Page.IsPostBack)
- {
- binddata();
- }
- }
- private void binddata()
- {
- SqlConnection con = new SqlConnection();
- ;
- con.ConnectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\odt\Documents\login.mdf;Integrated Security=True;Connect Timeout=30";
-
-
-
- SqlCommand cmd = new SqlCommand("SELECT * FROM log ", con);
- da = new SqlDataAdapter(cmd);
- da.Fill(ds);
- con.Open();
- cmd.ExecuteNonQuery();
- con.Close();
-
-
- htmlTable.Append("<table border='1'>");
- htmlTable.Append("<tr style='background-color:green; color: White;'><th>ID</th><th>Name</th><th>password</th></tr>");
- if (!object.Equals(ds.Tables[0], null))
- {
- if (ds.Tables[0].Rows.Count > 0)
- {
- for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
- {
- htmlTable.Append("<tr style='color: White;'>");
- htmlTable.Append("<td>" + ds.Tables[0].Rows[i]["Id"] + "</td>");
- htmlTable.Append("<td>" + ds.Tables[0].Rows[i]["username"] + "</td>");
- htmlTable.Append("<td>" + ds.Tables[0].Rows[i]["password"] + "</td>");
-
- ;
- htmlTable.Append("</tr>");
- }
- htmlTable.Append("</table>");
- hph.Controls.Add(new Literal { Text = htmlTable.ToString() });
- }
- else
- {
- htmlTable.Append("<tr>");
- htmlTable.Append("<td align='center' colspan='4'>There is no Record.</td>");
- htmlTable.Append("</tr>");
- }
- }
- }
- }
- }