Results 1 to 6 of 6

Thread: select query

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    382

    select query

    Code:
    Public con As OleDbConnection
        Public cmd As OleDbCommand
        Public dr As OleDbDataReader
    
    con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\student.mdb;")
            con.Open()
    str = "select name," & textbox1.text & " from Table1" 'textbox1.text="Address"
    
    cmd = New OleDbCommand(str, con)
    dr = cmd.ExecuteReader()
    
    While dr.Read()
    MsgBox(dr(0))
    MsgBox(dr(1))
    End While
    dr.Close()
    what wrong in this querry ?

    it give error in dr(1) ..
    Last edited by CatchItBaby; Aug 2nd, 2010 at 04:20 PM.

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: select query

    Well, does Table1 contain a column named "Address" ?

    You are missing a closing quote after Table1 in your SQL query text, however I imagine that was done during posting, and not in your real code, as it would not even run as it is above.

  3. #3
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: select query

    Doesn't the code editor report syntax errors?

    You have syntax errors both in SQL syntax and VB syntax.

    I seriously doubt you enter the Column name in your textbox1, and if you need to specify a criteria you must provide WHERE keyword:

    Code:
    SELECT ColumnName1, ColumnName2 FROM TableName WHERE ColumnNameN=Value;

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    382

    Re: select query

    sorry , i did typing mistake while posting code in vbforum

    Yes table contain column address

  5. #5
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: select query

    You can do dr(0) without .tostring ?
    Just questioning myself i don't have .net here.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  6. #6
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: select query

    Tell us the exception message.

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