473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Display sql database record in list view using c#

Hello, I want to display the content of my database in list view. The table has 5 columns however when I tried this code

Expand|Select|Wrap|Line Numbers
  1. string view = "Select * from cust_infor";
  2. SqlCommand cmd = new SqlCommand(view,FL.clsconnection.opencon());
  3.             SqlDataReader dr = cmd.ExecuteReader();
  4.             listView1.Items.Clear();
  5.  
  6.             while (dr.Read())
  7.             {
  8.                 listView1.Items.Add(dr[0].ToString()).SubItems.Add(dr[1].ToString());
  9.  
  10.            }
  11.  
It limits the display to 2 columns. List view will only show the first 2 columns. The code above won't let me add more indexes or subitems. Only up to 2 columns. Please help. Thanks
Oct 6 '12 #1
1 7568
Try this code
Expand|Select|Wrap|Line Numbers
  1. Tostring (SqlConnection con = new SqlConnection("Data Source=;Initial Catalog= ;Integrated Security= SSPI"))
  2. {
  3.     con.Open();
  4.     using (DataSet ds = new DataSet())
  5.     {
  6.         using (SqlDataAdapter adapter = new SqlDataAdapter(sql, con))
  7.         {
  8.             adapter.Fill(ds);
  9.         }    
  10.     }
  11. }
Nov 8 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: jorntk | last post by:
i have a php script that read from mysql and display then in textbox. I have problem with the way textbox display the data. <input type=text name="package_name" size=20 maxlength=10...
0
by: davebrad4d | last post by:
Please help me I am trying to port over some old 3rd party code (using XVT), and am using .net via managed c++. All my buttons and edit controls look great. However i can't get a virtual...
5
by: Praveen R | last post by:
Hi ! I am using a List view control to populate data onto. On the click event of the list view control, i need to find out whether the area clicked has any information of has no information. I...
0
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
3
by: meyo8185 | last post by:
hello guys.. i am new with javascripting and really lack of knowledge about it.. my lecturer asking me to insert or add the value that i already enter in the filed into a table locate really below...
2
by: baling | last post by:
Hi, everybody. I have some problem in my program. In this case i have a list view. In this list view there are some record. Now i want to save that record into database, but i don't know how....
3
by: > Adrian | last post by:
In VS 2003 I could sort a column in a list view using the code below, hover, in V2005 I get this error: Error 1 Using the generic type 'System.Collections.Generic.IComparer<T>' requires '1' type...
2
by: JJ | last post by:
OK - I asked this earlier but thought I'd solved it. Clearly not. I have a control that I need to display text from an sql database. The control is being used as a web part so can be placed on a...
0
by: =?Utf-8?B?U2V0aA==?= | last post by:
I have a simple test application with a list view using custom draw to change the text background color. The list view uses a background image which I set using LVBKIMAGE img =...
1
by: jollyguy77 | last post by:
Hi, I have just started to learn in .net. I want to show a list of filename along with the corresponding image (like pdf image for pdf files etc..). i will be getting the list of files from...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.