Click to See Complete Forum and Search --> : Select 0 records/Open a empty Recordset object


SameerShintre
December 20th, 1999, 04:53 AM
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

Chris Eastwood
December 20th, 1999, 05:03 AM
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

Crazy D @ Work
December 20th, 1999, 06:17 AM
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 :-)