Hi,
Dim strConn As String
Dim conn As SqlConnection
Dim drCustomer As SqlDataReader
Dim cmd As SqlCommand
strConn = "Server = " + Environment.Mac hineName + ";"
strConn += "Database = NorthWind;"
strConn += "Integrated Security = SSPI;"
conn = New SqlConnection(s trConn)
cmd = New SqlCommand("Sel ect * from Customers", conn)
conn.Open()
Dim chID As New ColumnHeader
chID.Text = "Customer ID"
chID.Width = 70
Dim chCompany As New ColumnHeader
chCompany.Text = "Company Name"
chCompany.Width = 200
Dim chContact As New ColumnHeader
chContact.Text = "Contact Name"
chContact.Width = 150
ListView1.Colum ns.Add(chID)
ListView1.Colum ns.Add(chCompan y)
ListView1.Colum ns.Add(chContac t)
ListView1.View = View.Details
drCustomer = cmd.ExecuteRead er
Do While drCustomer.Read
Dim lvi As New
ListViewItem(dr Customer.Item(" CustomerID").To String)
lvi.SubItems.Ad d(drCustomer.It em("CompanyName ").ToString )
lvi.SubItems.Ad d(drCustomer.It em("ContactName ").ToString )
ListView1.Items .Add(lvi)
Loop
conn.Close()
Ken
--------------------
"SA" <te**@test.co m> wrote in message
news:ek******** ******@TK2MSFTN GP12.phx.gbl...
My listview has 3 columns i.e. name, populaiton, and country code in
order.
I use following code to insert data into listview and I find that I can't
assign which subitem related to related field. e.g. assign population to
column2. In vb 6, I can do it by "subitems(i ). How about in .net? thx.
i = 0
While MyDataAdapter.R ead
ListView1.Items .Add("")
ListView1.Items (i).Text = CStr(MyDataAdap ter("name"))
ListView1.Items (i).SubItems.Ad d(MyDataAdapter ("population "))
ListView1.Items (i).SubItems.Ad d(MyDataAdapter ("CountryCode") )
i = i + 1
End While