Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I've written some code to pull information from my SQL server and it is working marvelously, however I don't have the slightest idea how it can populate the actual image within SQL.

VB
UserListView.View = View.Details
        UserListView.GridLines = True
        Dim strQ As String = String.Empty
        strQ = ("SELECT tblUser.UserPicture AS 'Picture', tblUser.EmployeeNum AS 'Employee#', tblUser.UserLastName AS 'Last Name', tblUser.UserFirstName AS 'First Name', tblUser.UserEmail AS 'Email', tblUser.UserInactive AS 'Inactive' FROM tblUser INNER JOIN tblUserTerminals ON tblUser.XID=tblUserTerminals.UserXID WHERE tblUserTerminals.TerminalXID = '" & ValueTextBox.Text & "' AND tblUser.EmployeeNum <> '0' ORDER BY tblUser.UserLastName, tblUser.UserFirstName ASC")
        command = New SqlCommand(strQ, con2)
        DA = New SqlDataAdapter(command)
        DS = New DataSet
        DA.Fill(DS, "Table")
        Dim i As Integer = 0
        Dim j As Integer = 0
        'Adds the columns to UserListView
        For i = 0 To DS.Tables(0).Columns.Count - 1
            UserListView.Columns.Add(DS.Tables(0).Columns(i).ColumnName.ToString())
        Next
        'Adds the items to UserListView
        For i = 0 To DS.Tables(0).Rows.Count - 1
            For j = 0 To DS.Tables(0).Columns.Count - 1
                ItemColl(j) = DS.Tables(0).Rows(i)(j).ToString()
            Next
            Dim lvi As New ListViewItem(ItemColl)
            UserListView.Items.Add(lvi)
            Dim lviimage As New ListViewItem(ItemColl)

        Next



Any help would be greatly appreciated!

Thanks!
Posted
Comments
Sergey Alexandrovich Kryukov 29-Apr-15 17:00pm    
What is "listviewbox"?
And what would you mean by "ListView". Which one? Full type name, please.
—SA

1 solution

Major part of this question has been asked so many times that it would be bad to answer it again. Please see: http://www.codeproject.com/search.aspx?q=database+store+%28bitmaps+OR+images+OR+pictures%29+%28%22ADO.NET%22+OR+%22C%23%22+OR+%22VB.NET%22%29&doctypeid=1%3b5[^].

In many cases, such as with Web sites/application, it would be more practical to store just the image names and store the images themselves in the file system on server side.

Remaining problem is showing images in ListView. But the problem is: you did not specify which type do you mean, exactly. There are different unrelated (but similar) types using this name as a simple type name, so which one? I don't want any guesswork. Always specify full type name. Better yet, just read documentation on this type.

[EDIT]

As to presenting images in the instance of System.Windows.Forms.ListView, you can get the idea in this MSDN articles:
https://msdn.microsoft.com/en-us/library/system.windows.forms.listview.smallimagelist%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.listview.largeimagelist%28v=vs.110%29.aspx[^].

Main thing here is: you have to collect all images in one object of the type System.Windows.Forms.ImageList, the property of the ListView. Then the images shown in the list view will be defined by the indices assigned to the property ImageIndex of the item.

The presentation of the list view depends on the value of View property:
https://msdn.microsoft.com/en-us/library/system.windows.forms.listview.view%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.view%28v=vs.110%29.aspx[^].

—SA
 
Share this answer
 
v2
Comments
kaniption 30-Apr-15 8:35am    
The images are uploaded via the application I'm building to the server and then pulled via open connection to the application into pictureboxes in various parts of my app. I understand how to pull from the server to a picturebox, what I can't comprehend is pulling it to display with the appropriate item in my listview within the code I have. The images I'm pulling are bitmaps.

That part isn't the problem and working fine. My listview even works fine pulling the data and displays everything, but the picture.
Sergey Alexandrovich Kryukov 30-Apr-15 9:32am    
Give me the type name.
—SA
kaniption 30-Apr-15 10:43am    
I'm not sure what you mean by "type". Please excuse my noobness - I'm fairly new to VB.

The ListView I am working with has a View of "Large Icon" and my ListView is entitled "UserListView"
Sergey Alexandrovich Kryukov 30-Apr-15 10:59am    
No problem. Just please give me the full type name. The name from the library, not the name of your derived class, of course (which could be anything).

Examples: System.Windows.Forms.Button or System.Windows.Controls.Button — two different names of similar but totally unrelated types.

—SA
kaniption 30-Apr-15 16:36pm    
Ah, I see, okay thank you.

It says under Property "System.Windows.Forms.Listview"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900