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
Jack Cheetham
NA
1
2.5k
Populating a ListView with a DataTable
May 5 2015 10:24 AM
Hi,
can anyone help me? I'm trying to populate a ListView on a winForms application with a Data set which I am retrieving from a Database. The ListView gets populated when a button is clicked by a user.
Here is my code:
private void button2_Click_1(object sender, EventArgs e)
{
{
lstvw1.View = View.Details;
string connectionString = null;
string server = null;
SqlConnection con;
server = System.Environment.GetEnvironmentVariable("Corp Report Server");
connectionString = "Data Source=" + server + ";Initial Catalog=Corp_Rpt;Integrated Security=True";
con = new SqlConnection(connectionString);
SqlDataAdapter da = new SqlDataAdapter("Select Top 5 * From Corp_Rpt.Common.VW_BOOKINGS", con);
DataTable dt = new DataTable();
lstvw1.Items.Clear();
da.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
ListViewItem lvi = new ListViewItem(dr[0].ToString());
for (int i = 0; i < dt.Columns.Count; i++)
{
lvi.SubItems.Add(dr[i].ToString());
}
lstvw1.Items.Add(lvi);
}
Thanks in advance,
Jack.
Reply
Answers (
1
)
How to count the the number of row in sql table from C#
How to resolve ATR chart series issue