CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 1999
    Posts
    5

    Select 0 records/Open a empty Recordset object

    hi,
    I am creating a VB Form which in used only to insert a new Customer record using ADO / Recordset in the database.

    I want to open the recordset object with zero records.
    so i am using a code

    Dim cn as Connection
    Dim rs as Recordset
    Dim lsSQL as string
    '....
    '....
    lsSQL = "select * from Customer_Master where 1=2 "
    rs.open = lsSQL,cn,adOpenKeyset, adLockOptimistic
    'open the recordset with 0 records , since 1=2 will fail for all records in database.
    '...
    '...
    rs.Addnew
    '... set the recordset fields
    rs.Update
    rs.Close




    Is there some better way than this, other than using the SQL Insert statement. !!!

    Thanks

    Sameer


  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Select 0 records/Open a empty Recordset object

    What's wrong with using the SQL Insert Statement ? It's going to be a lot faster than the way you're proposing. The building an empty recordset and then populating it with 'AddNew' requires many more calls to the database than a simple 'Insert' (VB would have to retrieve all the column info for instance).

    I'd recommend that you either use a stored procedure or a standard SQL Insert statement.


    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  3. #3
    Join Date
    Apr 1999
    Location
    Netherlands
    Posts
    181

    Re: Select 0 records/Open a empty Recordset object

    I agree with Chris.
    But if you still want to open an empty recordset, you can try "SELECT * FROM mytable WHERE myfield = -1" (assuming that myfield is numeric-positive values)

    Crazy D @ Work :-)

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

Featured