473,406 Members | 2,378 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,406 software developers and data experts.

ListView Data Binding Error

Dear all,

I'm trying to do a data binding for a ListView and I rewrite the code
from some example but there is a error while I execute.

Can anybody tell me what's wrong with it?? Thank you!!

Alan

Error message is

"An unhandled exception of type 'System.IndexOutOfRangeException'
occurred in system.data.dll

Additional information: Index out of arrary。"

at '*****' below
lv1=Listview

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim dbCon As New OleDbConnection
Dim conStr As String
Dim da As OleDbDataAdapter
Dim ds As DataSet
Dim myData As OleDbDataReader
Dim oleCmd As OleDbCommand

conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Documents and Settings\alan\My Documents\Visual Studio
Projects\FunctionTest\test.mdb;" & _
"Persist Security Info=False"

dbCon.ConnectionString = conStr
oleCmd = New OleDbCommand("Select a.order_id, b.food_code,
b.price from [order] a, order_detail b where a.order_id=b.order_id")
oleCmd.Connection = dbCon
dbCon.Open()
myData = oleCmd.ExecuteReader
lv1.Clear()

Dim sht As Short
Dim lvCol As ColumnHeader

For sht = 0 To myData.FieldCount() - 1
lvCol = New ColumnHeader
lvCol.Text = myData.GetName(sht)
lv1.Columns.Add(lvCol)
Next
lvCol = Nothing

Dim itm As ListViewItem
Dim sht1 As Short

Do While myData.Read
itm = New ListViewItem

***** If myData.IsDBNull(myData(0)) Then
itm.Text = ""
Else
itm.Text = myData(0)
End If

For sht1 = 1 To myData.FieldCount() - 1
If myData.IsDBNull(sht1) Then
itm.SubItems.Add("")
Else
itm.SubItems.Add(myData.GetString(sht1))
End If
Next sht1

lv1.Items.Add(itm)

Loop

End Sub
End Class
Nov 20 '05 #1
0 1335

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Vanessa | last post by:
With this program I can do one selection, but upon the second I get an error where ///////////////// is indicated. Please help. using System; using System.Drawing; using System.Collections;...
1
by: Peter | last post by:
Hello Thanks for reviewing my question. I noticed that the ListView properties do not offer any Data Binding option. Did Microsoft forget this Many Thank Peter
6
by: ReMEn | last post by:
I was wondering how I can use a listview effectively in managed c++ ..net. Basically I'm trying to get the index of the selected item in the list view, then get the "tag" attribute of that item to...
3
by: alan | last post by:
What I would like to do is like that, a ListView data binding with a dataset which list all records of a table( for example the table list all the information of a student student_id, name,...
4
by: Lasse Eskildsen | last post by:
Hi, Is there an easy way to load the content of a dataset into a listview with a few columns? Thanks! -- Lasse
1
by: OpticTygre | last post by:
I have a listview where users can add items via a textbox and an 'add' button. The problem is, the code below doesn't work for keeping duplicates entered. If I create a ListViewItem with the same...
2
by: Joe | last post by:
Anyone can suggest the best method of reading XML and adding data to ListView? Here is the xml data structure:: <xml> <site> <url>http://www.yahoo.com</url> <lastupdate></lastupdate>...
9
by: Kadett | last post by:
Hi all, I have following problem: I'm creating a ListView (Details) control at run-time and filling it with some records (let's say 10 000). This operation seems to be quite fast, but when I call...
1
by: Monty M. | last post by:
Does anyone know how to perform two way data binding between a combo box and a listview. The listview is bound to a dataset table in code: Binding Bind = new Binding(); DataTable dt;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.