Ambigious Match Exception was unhandled

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello,<br/>
I am trying to make a program for Product Entry form in Vb.net 2010. However I seem to get a error and I have no clue how to fix this. When I run my application it would popup an error, my code is below which I use in Product entry form.
<div style="color:black; background-color:white
<pre><span style="color:blue Imports System.Data.OleDb

<span style="color:blue Public <span style="color:blue Class frmProductForm

<span style="color:blue Dim conn <span style="color:blue As <span style="color:blue New OleDbConnection
<span style="color:blue Dim myqry <span style="color:blue As <span style="color:blue String = <span style="color:blue Nothing
<span style="color:blue Dim mycmd <span style="color:blue As <span style="color:blue New OleDbCommand
<span style="color:blue Dim mydr <span style="color:blue As OleDbDataReader
<span style="color:blue Dim str <span style="color:blue As <span style="color:blue String = <span style="color:blue Nothing

<span style="color:blue Private <span style="color:blue Sub frmProductForm_Load(<span style="color:blue ByVal sender <span style="color:blue As <span style="color:blue Object, <span style="color:blue ByVal e <span style="color:blue As System.EventArgs) <span style="color:blue Handles <span style="color:blue Me.Load
<span style="color:blue Call ListView1settings()
<span style="color:blue Call Conn2DB()
<span style="color:blue Call FillListview()
<span style="color:blue End <span style="color:blue Sub

<span style="color:blue #Region <span style="color:#a31515 "FillListView"
<span style="color:blue Sub FillListview()
ListView1.Items.Clear()
myqry = <span style="color:#a31515 "SELECT * from Product ORDER BY PID ASC"
mycmd = <span style="color:blue New OleDbCommand(myqry, conn)
mydr = mycmd.ExecuteReader

<span style="color:blue While mydr.Read
<span style="color:blue With ListView1
.Items.Add(mydr(<span style="color:#a31515 "PID"))
<span style="color:blue With .Items(.Items.<span style="color:blue Count - 1).SubItems
.Add(mydr("PName"))<br/> .Add(mydr("TileSize")) << From their the popup error start<br/> .Add(mydr("PackOfBox"))<br/> .Add(mydr("SqM"))<br/> .Add(mydr("Box"))<br/> .Add(mydr("UnitPrice"))<br/> .Add(mydr("UnitsInStock")<br/> .Add(mydr("UnitsOnOrder"))
<span style="color:blue End <span style="color:blue With
<span style="color:blue End <span style="color:blue With
<span style="color:blue End <span style="color:blue While
<span style="color:blue End <span style="color:blue Sub
<span style="color:blue #End Region

<span style="color:blue #Region <span style="color:#a31515 "ListView1Settings"
<span style="color:blue Sub ListView1settings()
<span style="color:blue With ListView1.Columns
.Add("PID", 50, HorizontalAlignment.Left)<br/> .Add("PName", 100, HorizontalAlignment.Left)<br/> .Add("Tile Size", 100, HorizontalAlignment.Left)<br/> .Add("Pack of Box", 100, HorizontalAlignment.Left)<br/> .Add("SqM", 100, HorizontalAlignment.Left)<br/> .Add("Box", 100, HorizontalAlignment.Left)<br/> .Add("Unit Price", 100, HorizontalAlignment.Left)<br/> .Add("Units InStock", 100, HorizontalAlignment.Left)<br/> .Add("Units OnOrder", 100, HorizontalAlignment.Left)
<span style="color:blue End <span style="color:blue With
<span style="color:blue End <span style="color:blue Sub
<span style="color:blue #End Region
....
....
<span style="color:blue End <span style="color:blue Class
[/code]

the popup error is at line {.Add(mydr(<span style="color:#a31515 "TileSize"))} and further for below line, the error which occur at run time of the application.

<div style="color:black; background-color:white
<pre>System.Reflection.AmbiguousMatchException was unhandled
Message=Overload resolution failed because no <span style="color:blue Public <span style="color:green Add can be called with these arguments:
<span style="color:green Public Function Add(text As String) As System.Windows.Forms.ListViewItem.ListViewSubItem:
Argument matching parameter <span style="color:green text cannot convert from DBNull to String.
<span style="color:green Public Function Add(item As System.Windows.Forms.ListViewItem.ListViewSubItem) As System.Windows.Forms.ListViewItem.ListViewSubItem:
Argument matching parameter <span style="color:green item cannot convert from DBNull to ListViewSubItem.
[/code]


I have no clue how to fix this. and also for how to control the "DBNull" in our form.
Thanks in advance.<br/>
<br/>

View the full article
 
Back
Top