TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Oladotun Obileye
NA
98
19.4k
How to retreive data from database to a table in asp webform
May 7 2019 1:02 AM
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"
;
//con.Open();
// SqlCommand cmd = new SqlCommand();
//cmd.CommandText = "select * from [log] ";
SqlCommand cmd =
new
SqlCommand(
"SELECT * FROM log "
, con);
da =
new
SqlDataAdapter(cmd);
da.Fill(ds);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
//cmd.Connection = con;
// SqlDataReader dt = cmd.ExecuteReader();
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("<td>" + ds.Tables[0].Rows[i]["ContactNo"] + "</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>"
);
}
}
}
}
}
Reply
Answers (
1
)
Remove Validation when the textbox is disable and empty MVC
Login Page in MVC using WEB API