473,569 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.IndexOu tOfRangeExcepti on'
occurred in system.data.dll

Additional information: Index out of arrary。"

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

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

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

conStr = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=C:\Docum ents and Settings\alan\M y Documents\Visua l Studio
Projects\Functi onTest\test.mdb ;" & _
"Persist Security Info=False"

dbCon.Connectio nString = conStr
oleCmd = New OleDbCommand("S elect a.order_id, b.food_code,
b.price from [order] a, order_detail b where a.order_id=b.or der_id")
oleCmd.Connecti on = dbCon
dbCon.Open()
myData = oleCmd.ExecuteR eader
lv1.Clear()

Dim sht As Short
Dim lvCol As ColumnHeader

For sht = 0 To myData.FieldCou nt() - 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.FieldCou nt() - 1
If myData.IsDBNull (sht1) Then
itm.SubItems.Ad d("")
Else
itm.SubItems.Ad d(myData.GetStr ing(sht1))
End If
Next sht1

lv1.Items.Add(i tm)

Loop

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

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

Similar topics

6
2520
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; using System.ComponentModel; using System.Windows.Forms; using System.Data;
1
2479
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
1545
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 invoke data in other area of my app. Here's some example code: ////////////////////////////////////// private: System::Void...
3
3775
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, tel....etc). Besides, there are some textbox will display the student information when I click on one of the record on the ListView so that I can update...
4
17090
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
2764
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 data in it as another ListViewItem, why aren't those two items considered equal? For example, a Debug.Writeline(lvItem1.Equals(lvItem2)) would...
2
7528
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> <check>1</check>
9
4468
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 Controls.Add(list), where list is my ListView control, then program hangs for minute. It seems like this time depends on number of records added to...
1
9810
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; Field_LV.DataContext = dt; Field_LV.SetBinding(ListView.ItemsSourceProperty, Bind);
0
7697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8120
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7968
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6283
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.