|
-
December 20th, 1999, 05:53 AM
#1
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
-
December 20th, 1999, 06:03 AM
#2
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
-
December 20th, 1999, 07:17 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|