Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am adding to a listview with no problem but when I try and add a field of type "text" from access database with:

 

ListView1.Items(i).SubItems.Add(myReader("description"))

 

I get the following error!

 

An unhandled exception of type 'System.Reflection.AmbiguousMatchException' occurred in microsoft.visualbasic.dll

 

Additional information: No accessible overloaded 'ListViewSubItemCollection.Add' can be called without a narrowing conversion.

 

what does that mean and how can i fix it?

 

Thanks

  • *Experts*
Posted

Try this:

ListView1.Items(i).SubItems.Add(myReader("description").ToString())

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted

Remember that every column in a DataSet/DataReader is an object. That object can be pretty much any type. Luckily, all objects have the ToString() method. If your column might be NULL (NULL in your database, System.DBNull.Value in code), you may want to trap for that and use "string.Empty" instead of column.ToString().

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted

I'll try to answer it before it's asked :)

 

If myReader("description") = System.DBNull.Value Then
   ListView1.Items(i).SubItems.Add(string.Empty) 
Else
   ListView1.Items(i).SubItems.Add(myReader("description").ToString()) 
End If

 

Of course, if the description is null, you may not want to add it at all. I'm just showing how you could detect null and add an empty string instead. By the way, that code may not compile - I typed it by hand (not in the IDE) but it should be close

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...