Results 1 to 9 of 9

Thread: SQL behaves strange

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    255

    SQL behaves strange

    Hi there,

    I develop a database application where I communicate using VB 2010 epxress to MS Access 10 DB.
    I can connect, download and display content of tables.
    When I use the reader and sql statements like "select a,b from table" I receive data.
    However, when I use the Oledbdataadapter it only works with sql statement like "select * from table". Es soon as I replace the "*" with detailed fields I do not recieve any data.

    How could I resolve this?

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SQL behaves strange

    Welcome to the forum!

    What are the actual field names you are trying to use?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    255

    Re: SQL behaves strange

    Quote Originally Posted by szlamany View Post
    Welcome to the forum!

    What are the actual field names you are trying to use?
    I have marked the line that results in no records with "<<<<< ".
    Here is the code
    Private Sub KundenID()
    'Create the commands.
    Dim queryString As String = "select * from Kundenliste"
    'Dim queryString As String = "select Position from Kundenliste" <<<<<<<< no records are recieved
    'Datenadapter aus der Datenbank füllen
    Dim KundenAdapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(queryString, connection)
    KundenAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

    'DatenTable füllen
    Dim Kundentabelle As New DataTable("Kundenliste")
    KundenAdapter.Fill(Kundentabelle)
    DG_Auftrag.DataSource = Kundentabelle ' fills DataGrid
    'MsgBox(Kundentabelle.Rows(0).Item(0))
    For i = 0 To Kundentabelle.Rows.Count - 1
    CB_Firma.Items.Add(Kundentabelle.Rows(i).Item(1)) 'fills combobox
    Next

    End Sub

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SQL behaves strange

    Seems POSITION might be a reserved word

    https://msdn.microsoft.com/en-us/library/ms189822.aspx

    Try instead this syntax:

    Code:
    Dim queryString As String = "select [Position] from Kundenliste"
    see if that works.

    If it does I would recommend changing those fieldnames to words that are not reserved - you do not want to fight that battle.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    255

    Re: SQL behaves strange

    Hi
    I have now tried with this line:
    Dim queryString As String = "select [Auftrags ID] from Kundenliste" '<<<<<<<< no records are recieved
    but do still get no records downloaded.

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SQL behaves strange

    There cannot be a space in a field name so that syntax will certainly not work.

    You said the field was POSITION?

    And that you were trying to get ONE FIELD.

    Be specific please.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    255

    Re: SQL behaves strange

    Hi,

    your comment helped I went through this and found out:
    It was a stupid mistake that was carried through several programs: A wrong table was used that did not have those columns.

  8. #8
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,836

    Re: SQL behaves strange

    Quote Originally Posted by smktec View Post
    Hi,

    your comment helped I went through this and found out:
    It was a stupid mistake that was carried through several programs: A wrong table was used that did not have those columns.
    That makes me wonder if you have error handling in your program. Something like that, select columns that do not exist, should have failed and could be trapped I would think.
    Please remember next time...elections matter!

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    255

    Re: SQL behaves strange

    you may be right.
    I found this error at one place and it worked after I fixed it. But this was probably misleading. Later I found that VB crashed or ran into an error because an .exe file could not be copied into the debug folder. Only after deleting or waiting for some time I could restart (I put this into another thread). I also found that a combobox was called several times (by itself???). This could also have contributet. Now I have eliminated all these errors and it seems to work stable.

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