Results 1 to 38 of 38

Thread: [RESOLVED] Received error when I click button

  1. #1

    Thread Starter
    Banned
    Join Date
    May 2008
    Posts
    461

    Resolved [RESOLVED] Received error when I click button

    I need your help, I am trying to get over this problem and I don't know why I get an error message everytime when I click the button.



    Here it the code:

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
    Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * From Table1", "Put an actual connection string here.  THIS SHOULD NOT BE COPIED MINDLESSLY AND EXPECTED TO WORK")
            Dim dt As New DataTable
            da.Fill(dt)
    
            Dim img As Image
    
            For Each row As DataRow In dt.Rows
                img = Image.FromStream(New IO.MemoryStream(DirectCast(row.Item("NameOfImageColumn").Value, Byte())))
                'Do something with the image
            Next
    End Sub


    Error: Format of the initialization string does not conform to specification starting at index 0.



    It shows highlight on Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * From Table1", "Put an actual connection string here. THIS SHOULD NOT BE COPIED MINDLESSLY AND EXPECTED TO WORK") as statement. What can I do to get this fix??



    Thanks,
    Mark
    Last edited by Mark107; Jun 28th, 2008 at 10:52 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Received error when I click button

    You are kidding me, right? Did you actually read that code? Look at the second argument you're passing to your OleDbDataAdapter constructor:
    Put an actual connection string here. THIS SHOULD NOT BE COPIED MINDLESSLY AND EXPECTED TO WORK
    Despite the fact that that explicitly tells you to put an actual connection string there, you seem to have mindlessly copied it and expected it to work.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Banned
    Join Date
    May 2008
    Posts
    461

    Re: Received error when I click button

    Thanks for your reply JMC. I am not really kidding to you, what shall I do with that second argument you have shown on your post??



    Shall I input the name of the columns from my database??




    Thanks,
    Mark

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Received error when I click button

    No, you shall do what it specifically tells you to do:
    Put an actual connection string here.
    You can get the connection string format for your data source at www.connectionstrings.com. Note that it will give you the format only. It's still up to you to put the correct parameter values into it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Banned
    Join Date
    May 2008
    Posts
    461

    Re: Received error when I click button

    Ok thanks, I am using microsoft access 2007 so why did you post the link to find out the connection string format for my data source?? It won't tell me on that site where I have take a look so hope we can get this resolve if you please tell me an instructions what I do with??


    The link you post gave me no where to go.


    Thanks,
    Mark

  6. #6

    Thread Starter
    Banned
    Join Date
    May 2008
    Posts
    461

    Re: Received error when I click button

    Code:
    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Persist Security Info=False;

    Is that connection string format for my data source where I should replace Put an actual connection string here. on my statement??



    Thanks,
    Mark

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Received error when I click button

    Quote Originally Posted by Mark107
    Code:
    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Persist Security Info=False;

    Is that connection string format for my data source where I should replace Put an actual connection string here. on my statement??



    Thanks,
    Mark
    Did you try it? Did it work? If it did then the answer is "yes", otherwise the answer is "no".
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: Received error when I click button

    LOL, i'm the one who gave him the original code. I thought i'd made it pretty clear that it shouldn't be copied and pasted, but oh well.

    Anyway, Mark, how about you answer a few questions instead:

    Is this a multi-user program?

    If your answer was YES, then is the database file being stored on a network PC?

    If your answer was NO, then we will assume that it will be located in Application.StartupPath, and probably without any kind of security, in which case, you could try this:

    Code:
    Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * From Table1", "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\myAccess2007file.accdb;Persist Security Info=False;")

  9. #9

    Thread Starter
    Banned
    Join Date
    May 2008
    Posts
    461

    Re: Received error when I click button

    Yes I did and it's nearly fix but there is another error message, The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.



    It show the yellow highlight on da.Fill(dt) statement. I don't see what's the problem is??


    Thanks,
    Mark

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Received error when I click button

    Quote Originally Posted by Mark107
    Yes I did and it's nearly fix but there is another error message, The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.



    It show the yellow highlight on da.Fill(dt) statement. I don't see what's the problem is??


    Thanks,
    Mark
    Do you have Access 2007 installed on your machine? If not then you will have to install the Office 2007 driver pack, downloadable from Microsoft, to install the Access 2007 OLEDB provider.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11

    Thread Starter
    Banned
    Join Date
    May 2008
    Posts
    461

    Re: Received error when I click button

    I only have microsoft access 2002 on my machine. Can you post a link on here because i took a look on google and none of them have found??




    Thanks,
    Mark

    Quote Originally Posted by jmcilhinney
    Do you have Access 2007 installed on your machine? If not then you will have to install the Office 2007 driver pack, downloadable from Microsoft, to install the Access 2007 OLEDB provider.

  12. #12

    Thread Starter
    Banned
    Join Date
    May 2008
    Posts
    461

    Re: Received error when I click button

    I have rename from Provider=Microsoft.ACE.OLEDB.12.0;Data Source= to Provider=Microsoft.Jet.OLEDB.4.0;Data source= so when I run the form and when I click the button, it highlighting on da.Fill(dt) as statement with the error OleDBExpection was unhandled Not a valid file name.


    It do not means I am using old version but something is incorrect and need to fix??


    Thanks,
    Mark

  13. #13
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: Received error when I click button

    Hi Mark,

    The database which you want to connect to, is Access 2007. Your local computer only has the neccessary files to talk to Access versions upto and including 2003. Therefore, in order for your local machine and indeed your code, to communicate with your database, you will need to install or upgrade the office libraries/certain Office files upon your computer.

    One way of doing this would be to upgrade your local copy of Office 2002 to an Office 2007 version, another way would be to install Office 2007 onto your computer alongside your existing Office 2002 version and the third and perhaps easiest option would be to install the Office 2007 driver pack which has already been suggested above.

    As for your connection string and related to your last question/post there, I would suggest you research what a connection string is to begin with. First off, this is direct from MS:
    A connection string is a string version of the initialization properties needed to connect to a data store and enables you to easily store connection information within your application or to pass it between applications. Without a connection string, you would be required to store or pass a complex array of structures to access data.
    Basically, to make a connection to a database, several items of information are required to be known. The first is the type of the database, the second is the location of the database, then you may have valid login or authorisation information for this specific database . These are the basic items of information required before VB will make the database connection. A connection string is a ";" delimited string representation of these items of information.

    Once you grasp this part, the connectionstrings site, and indeed the individual ; separated parts of the connectionstring examples shown upon that site should fall slowly into place. To further explain your last post, the provider connectionstring specifier details the type of database you are wanting to connect to. Using the following, once you've set your machine up to talk to Office 2007 applications, will allow you to connect specifically to an Office 2007 Access database:
    Code:
    Provider=Microsoft.ACE.OLEDB.12.0;
    Next up, the Data Source specifier details the location of your database, so you need to add this in after your equals sign, like this:
    Code:
    Data Source=C:\myFolder\myAccess2007file.accdb
    It looks as though the connection string in your post 6 may well work if that database location is right and you have your machine setup to communicate with Office 2007 applications properly.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  14. #14

    Thread Starter
    Banned
    Join Date
    May 2008
    Posts
    461

    Re: Received error when I click button

    Thanks for your alex_read, unfornately there is no package for win 2000 where I am using on. However I find other useful code which let me reading information from the database.


    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
             Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * From Table1", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\db1_test.mdb;Persist Security Info=False;")
            Dim dt As New DataTable
            da.Fill(dt)
    
            Dim img As Image
    
            For Each row As DataRow In dt.Rows
                img = Image.FromStream(New IO.MemoryStream(DirectCast(row.Item("Images").Value, Byte())))
                'Do something with the image
            Next
    
    End Sub


    When I run the form and when I click the button, I have an error message saying Public member 'Value' on type 'Byte()' not found. It show the highlight on img = Image.FromStream(New IO.MemoryStream(DirectCast(row.Item("Images").Value, Byte()))) as statement.


    Please can you help to get this fix??





    Thanks,
    Mark
    Last edited by Mark107; Jun 29th, 2008 at 11:00 AM.

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Received error when I click button

    Are you developing the app on what system and office verison? Is the db located on a different 2k system?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  16. #16

    Thread Starter
    Banned
    Join Date
    May 2008
    Posts
    461

    Re: Received error when I click button

    The office version is 2003 and the os is win 2000 so I prefer to use Microsoft.Jet.OLEDB.4.0;Data Source which it will works. However, when I run the form and when I click the button, I have an error message saying Public member 'Value' on type 'Byte()' not found. It show the highlight on img = Image.FromStream(New IO.MemoryStream(DirectCast(row.Item("Images").Value, Byte()))) as statement.


    Please can you help to get this fix??





    Thanks,
    Mark

  17. #17
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: Received error when I click button

    Now I'm confused as above you put "Ok thanks, I am using microsoft access 2007"

    ANyhow with your last point there, could your datatable possibly contain NULL values / is it possible one of your rows does not have an entry in the images column at all?

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  18. #18
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Received error when I click button

    Are you using a *.accdb Access database file or an *.mdb Access database file?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  19. #19

    Thread Starter
    Banned
    Join Date
    May 2008
    Posts
    461

    Re: Received error when I click button

    Sorry I typed by my mistake. I should have input "Ok thanks, I am using microsoft access 2002" in the first place. Anyway, I believe they could work in both ways and I think the rows do have entry in the images column but the images do not shown on my listview.



    Hope there is a way to get it resolve.


    Thanks,
    Mark


    Quote Originally Posted by alex_read
    Now I'm confused as above you put "Ok thanks, I am using microsoft access 2007"

    ANyhow with your last point there, could your datatable possibly contain NULL values / is it possible one of your rows does not have an entry in the images column at all?

  20. #20

    Thread Starter
    Banned
    Join Date
    May 2008
    Posts
    461

    Re: Received error when I click button

    I am using .mdb access database file.

    Quote Originally Posted by RobDog888
    Are you using a *.accdb Access database file or an *.mdb Access database file?

  21. #21
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Received error when I click button

    Ok then the connectionstring shouldnt be the issue here. The line of code ...
    Code:
    img = Image.FromStream(New IO.MemoryStream(DirectCast(row.Item("Images").Value, Byte())))
    Is where you are generating your error so that shold be looked at for correcting.

    So do you have "row.Item("Images").Value" actually show up in the intellisense? Is that the correct type to be casting the image data to?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  22. #22
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: Received error when I click button

    Then the Jet.OleDB.4.0 is the right connection provider to use definitely.

    Can you try with this code please? Does this get rid of that error?
    Code:
    For Each row As DataRow In dt.Rows
        If not (row.Item("Images") is nothing) then
            img = Image.FromStream(New IO.MemoryStream(DirectCast(row.Item("Images").Value, Byte())))
            'Do something with the image
        End If
    Next

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  23. #23

    Thread Starter
    Banned
    Join Date
    May 2008
    Posts
    461

    Re: Received error when I click button

    It is still the same error I have got, it pointing on img = Image.FromStream(New IO.MemoryStream(DirectCast(row.Item("Images").Value, Byte()))) said that MissingMemberExpection was Unhandled Public member 'Value' on type 'Byte()' not found.




    I have already input the name of the column which it is Images into my database.



    Something is not right that going into the same way round??



    Thanks,
    Mark

  24. #24
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: Received error when I click button

    I had this thread open way too long in a browser window so didn't see Rob's reply there. Ignore my post and follow his suggestion. The removal of .Value should sort your issue here.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  25. #25
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Received error when I click button

    I think this should work

    Code:
    img = Image.FromStream(New IO.MemoryStream(DirectCast(row.Item("Images"), Byte())))
    I only tested it for valid syntax but didnt mock up a populated dt.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  26. #26

    Thread Starter
    Banned
    Join Date
    May 2008
    Posts
    461

    Re: Received error when I click button

    Thanks for your advise, I have take a test with my form and when I click the button, there is no images and text data to displaying on my listview.



    http://img176.imageshack.us/img176/4246/imageuf1.jpg




    There is nothing on my listview as it is blank. What's going on, something is not right??



    Thanks,
    Mark

  27. #27
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Received error when I click button

    Step through your code to make sure you are returning records.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  28. #28

    Thread Starter
    Banned
    Join Date
    May 2008
    Posts
    461

    Re: Received error when I click button

    Code:
    Public Class Form1
    
        Dim xConn As sqlConn
        Public Shared item1 As New ListViewItem()
    
        Private Const LVM_FIRST As Long = &H1000
        Private Const LVM_SETEXTENDEDLISTVIEWSTYLE As Long = (LVM_FIRST + 54)
        Private Const LVS_EX_FLATSB As Long = &H100
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * From Table1", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\db1_test.mdb;Persist Security Info=False;")
            Dim dt As New DataTable
            da.Fill(dt)
    
            Dim img As Image
    
            For Each row As DataRow In dt.Rows
                img = Image.FromStream(New IO.MemoryStream(DirectCast(row.Item("Images").Value, Byte())))
                'Do something with the image
            Next
        End Sub
    End Class


    Code:
    Public Class sqlConn
    
        Friend WithEvents OLEConn As New System.Data.OleDb.OleDbConnection()
        Friend WithEvents OLEComm As New System.Data.OleDb.OleDbCommand()
    
        Private sqlString As String
        Private err As System.Exception
    
        Public Shared dataReturned As New ArrayList()
    
        Public Property db() As String
            Get
                db = "C:\\db1_test.mdb"
            End Get
            Set(ByVal Value As String)
                Value = db
            End Set
        End Property
    
        Public Property xOLE() As String
            Get
                xOLE = "Provider=Microsoft.Jet.OLEDB.4.0;Data source="
            End Get
            Set(ByVal Value As String)
                Value = xOLE
            End Set
        End Property
    
        Function connectMe(ByVal sqlString As String) As Boolean
            Try
                OLEConn.ConnectionString = xOLE & db
                OLEConn.Open()
                OLEComm.CommandText = sqlString
                Return True
            Catch err As System.Exception
                MsgBox(err.Message)
                Return False
            End Try
        End Function
    
        Function getData() As ArrayList
    
            OLEComm.Connection = OLEConn
    
            getData = New ArrayList()
    
            Dim d As OleDb.OleDbDataReader = OLEComm.ExecuteReader()
            Do While d.Read
                getData.Add(d("Images".ToString))
                getData.Add(d("Cars".ToString))
            Loop
    
            'Returns array collection
            dataReturned = getData
        End Function
    End Class
    Last edited by Mark107; Jun 29th, 2008 at 06:17 PM.

  29. #29

    Thread Starter
    Banned
    Join Date
    May 2008
    Posts
    461

    Re: Received error when I click button

    do you know what the problem is and how to fix it??




    Thanks,
    Mark

  30. #30
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: Received error when I click button

    Your sqlConn class is terrible. Do some research on Properties and how they should be coded. Just so you know, Get should return the variable, Set should assign it a value.

  31. #31
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Received error when I click button

    Here is how your db property should look. (You are currently hard coding in a value so the set will never change it)
    Code:
    Private m_db As String
    
    Public Property db() As String
        Get
            Return m_db
        End Get
        Set(ByVal value As String)
            m_db = value
        End Set
    End Property
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  32. #32

    Thread Starter
    Banned
    Join Date
    May 2008
    Posts
    461

    Re: Received error when I click button

    Thanks for your input RobDog, I have replaced the code you post on here but it is still the same where it was, no image to display on my listview.



    I don't know what I should do now, maybe I should post attachment then??


    Thanks,
    Mark

  33. #33
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Received error when I click button

    The property code was just an extra fix that may have helped with changing your connection to the db but ...

    If you want to attach your solution and database in zip format I'm sure it would be easier to test out your situation. Ps, remove the debug and Release folders to help reduce the size.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  34. #34

    Thread Starter
    Banned
    Join Date
    May 2008
    Posts
    461

    Re: Received error when I click button

    There you go! Hope you can be able to situations and get the problem fixed asap!





    Thanks,
    Mark
    Attached Files Attached Files

  35. #35

    Thread Starter
    Banned
    Join Date
    May 2008
    Posts
    461

    Re: Received error when I click button

    do anyone know how to fix this????????????????

  36. #36
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: Received error when I click button

    That's because you're never calling any code to output your database values to your listbox, all you have is a comment similar to "do something with the values here".

    This code will work providing you change where I have put "C:\Path" to the actual directory location your database is found within. Also don't use double \\ characters for this path. That is not needed.
    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
            ' Connect to the database and retreive the data required from Table1 into a datatable object.
            Dim da As New System.Data.OleDb.OleDbDataAdapter( _
                "SELECT Car, Images FROM Table1 ORDER BY Car DESC", _
                "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Path\db1_test.mdb;Persist Security Info=False;")
            Dim dt As New DataTable
            da.Fill(dt)
    
            ' Place a new imagelist control onto your form designer window. The following
            ' will assign the listview to read from this control.
            With listview1
                .LargeImageList = imagelist1      
                .SmallImageList = imagelist1
            End With
    
            Dim img As Image
            Dim intImageIndex as Integer = 0
    
            ' Loop through each row in the database.
            For Each row As DataRow In dt.Rows
                ' First off, check we have a record value within the Car column.
                If not string.IsNullOrEmpty(row.Item("Car")) Then
    
                    ' If there is an image contained within the row, retreive this into a new image object.
                    ' Next, add this image into the imagelist control & output the car name and image to the
                    ' listview as a newlist item. This last call references the image by index number, which
                    ' is kept track of in the intImageIndex variable - incremented upon each loop iteration.
                    If Not(row.Item("Images") is nothing) then
                        img = Image.FromStream(New IO.MemoryStream(DirectCast(row.Item("Images"), Byte())))
                        imagelist1.Images.Add(row.Item("Car").ToString, img)
                        listview1.Items.Add(row.Item("Car").ToString, intImageIndex)
                    Else
                        ' If we arrived at this point, we have a car record entry, but no image. Therefore
                        ' we will just output the info we do have into a new listview listitem.
                        listview1.Items.Add(row.Item("Car").ToString)
                    End If
                Else
                    ' If we arrived here at this point in the code, then no record beneath the Car column
                    ' exists for the row. Here we check if there's an image record and output that if 
                    ' existing in the same manner as above.
                    If Not(row.Item("Images") is nothing) then
                        img = Image.FromStream(New IO.MemoryStream(DirectCast(row.Item("Images"), Byte())))
                        imagelist1.Images.Add("{NULL Value}", img)
                        listview1.Items.Add("{NULL Value}", intImageIndex)
                    End If
                End If
    
                intImageIndex +=1
            Next
    
            If Me.ListView1.Items.Count >= 12 Then
                Me.VScrollBar1.Enabled = True
                ListView1.Scrollable = True ' I've altered this, I believe you want true here.
                VScrollBar1.Maximum = ListView1.Items.Count
            End If
        End Sub
    Last edited by alex_read; Jul 1st, 2008 at 03:02 PM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  37. #37
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Received error when I click button

    same thread?

    CodeGuru
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  38. #38

    Thread Starter
    Banned
    Join Date
    May 2008
    Posts
    461

    Re: Received error when I click button

    Thanks for your help alex_read, you have been awesome. We have finally found the situations to get it sorting so now it's resolve



    Thanks for the help, keep up the good work!



    Thanks,
    Mark

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width