Results 1 to 9 of 9

Thread: SELECT * Not Working For Access Database

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2008
    Posts
    84

    Angry SELECT * Not Working For Access Database

    for the first time i am havin this kind of issue, i tried some google'in but of none help.

    Code:
        Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Log("Application Started Successfully")
    
            Log("Attempting To Connect To Database", True)
    
            If dbConnect(Application.StartupPath & "\myDatabase.mdb") Then
                Log("Successfully Connected To Database", True)
            Else
                MessageBox.Show("Unable To Connect To Database Critical Error", APP_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error)
                Application.Exit()
            End If
    
            'Using cmd As New OleDb.OleDbCommand("INSERT INTO MY_SETTING VALUES(1, 'TEST', 'TEST')", Conn)
            '    Debug.Print("Record's Affected : " & cmd.ExecuteNonQuery())
            'End Using
    
            Using cmd As New OleDbCommand("SELECT * from MY_SETTING;", Conn)
                Debug.Print("Total ID : " & cmd.ExecuteNonQuery())
            End Using
    
        End Sub



    The weird problem is INSERT is working but Select is not working!
    Last edited by -RaJ-; Aug 29th, 2011 at 03:59 AM.

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

    Re: SELECT * Not Working For Access Database

    Please try posting your code again. Also, please explain what "not working" actually means.
    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
    Lively Member
    Join Date
    Aug 2008
    Posts
    84

    Re: SELECT * Not Working For Access Database

    ty, i have posted again, the only problem is "SELECT" is not working at all!

    here is image my my database


  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2008
    Posts
    84

    Re: SELECT * Not Working For Access Database

    any help?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2008
    Posts
    84

    Re: SELECT * Not Working For Access Database

    i even tried with sqlcompactce, and its the same

    INSERT WORKING but SELECT is not working!

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: SELECT * Not Working For Access Database

    what do you meant by "it's not working" ??? Did you get toast when you asked for OJ? Did your door suddenly fall off the hinges? Did the tires fall off your car? Or did your arms fall off? We are not mind readers. People seem to think we are for some reason... I don't know why... but it's a rumour that's been around for almost as long as I can remember. Not quite sure what you're expecting to happen... perhaps if you removed the eels from your hover craft...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2008
    Posts
    84

    Re: SELECT * Not Working For Access Database

    by not working i meant to say is its showing 0 record's affected for that query command

    Code:
            Using cmd As New OleDbCommand("SELECT * from MY_SETTING;", Conn)
                Debug.Print("Total ID : " & cmd.ExecuteNonQuery())
            End Using
    it must show some positive non zero values, in other word's its not able to select it !! to data reader

    DataReader is showing as

    .hasRow = False


    this error has never happened to me before!

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: SELECT * Not Working For Access Database

    That's because you're using the ExecuteNonQuery ... there were NO ROWS affected... you didn't CHANGE any rows... so yeah, that's what I would expect. Your datareader is showing no rows because you used the ExecuteNonQuery... and not the ExecuteReader...
    ExecuteNonQuery Documentation:
    http://msdn.microsoft.com/en-us/libr...enonquery.aspx

    ExecuteReader Documentation:
    http://msdn.microsoft.com/en-us/libr...utereader.aspx

    Might want to brush up on what each one does...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: SELECT * Not Working For Access Database

    Quote Originally Posted by -RaJ- View Post
    by not working i meant to say is its showing 0 record's affected for that query command

    Code:
            Using cmd As New OleDbCommand("SELECT * from MY_SETTING;", Conn)
                Debug.Print("Total ID : " & cmd.ExecuteNonQuery())
            End Using
    it must show some positive non zero values, in other word's its not able to select it !! to data reader

    DataReader is showing as

    .hasRow = False

    this error has never happened to me before!
    What is confusing is, do you want to return rows or a count of rows?

    Seeing this yet at the same time Total mixed with ID does not makes sense
    Code:
    Debug.Print("Total ID : " & cmd.ExecuteNonQuery())
    Looks like you want total row count which would be done as follows.

    Code:
    cmd.CommandText = "SELECT COUNT(*) From MY_SETTING"
    Dim CustCount = CLng(cmd.ExecuteScalar)
    If you want rows back and not a count then use cmd.ExecuteReader.

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