How to check Eof in VB.Net ?

  • Thread starter Thread starter ItsMe
  • Start date Start date
I

ItsMe

Hi,

I want to check whether the record exist or not based on my query, so i'll
be using OleDbCommand.
What is the best way to check on a huge table ? I used to write like this in
VB6.0...

---------------------------------------------------
Public Function SaveOrUpdate() As Boolean
sSQL = "SELECT * FROM AdmAllergy WHERE " & _
" CompanyCode = " & mQuotedStr(mCompanyCode) & _
" AND BranchCode = " & mQuotedStr(mBranchCode) & _
" AND Code = " & mQuotedStr(sCode)
Set oRs = TmpAdoSet(sSQL)
With oRs
If .EOF And .BOF Then
.AddNew
.Fields("CompanyCode") = Trim(mCompanyCode)
.Fields("BranchCode") = Trim(mBranchCode)
.Fields("Code") = Trim(sCode)
.Fields("CreatedBy") = Trim(mUserId)
Else
.Fields("EditedBy") = Trim(mUserId)
.Fields("EditedDate") = Format(Now, "yyyy-mm-dd hh:mm:ss")
End If
.Fields("Name") = Trim(Name)
.UpdateBatch
.Close
End With
SaveOrUpdate = True
Set oRs = Nothing
End Function
---------------------------------------------------

So, how do i write in VB.Net ? Want to open check record exist or not. If
exist then update other fields
or else add new record. I prefer to use OleDbCommand.

Any Help ?

Regards
=====================
Clock's wrong
=====================
 
Hi Itsme,
I think there are many ways, that depends on the way you use ADO.net.
The code you are now using is probably ado 2.6 or something.
In VB.net is used Ado.net it is a totaly different approach.
"Datasets, dataview, datarows and no recordsets."

I think that the best place to ask a question like this is in the
public dotnet adonet newsgroup.

I hope you have success
Cor
 
try desperately setting your system clock back to normal time.


Thanks cor,
i've done that. desperately waiting for an answer

Regards
 
Use OleDBCommand.ExecuteScalar and query the count. If the count of your
query is non-zero, it means the record exists. Then use
OleDbCommand.ExecuteNonQuery to insert a new record.

Alternatively, use DataSets !! Well, I would recommend that you first
understand ADO.Net before you embark on using it. It is different from
ADO2.7 by quite a margin both in architecture and style of programming and
needs special attention.
 
Besides using datasets as previiously mentioned, (which are quite helpful
and reflect that of ADO 2.x's Recordset Object) learn to use Enumerations
within datasets as well. You'll find your development time is cut down
(especially with typed datasets) when you use things like for each
statements, which will be helpful to you in more ways than you know.

Also, the dataset object (generated or not) exposes a ton of properties that
can do every concievable thing you want, including DataRelationships which I
think are one of the most powerful tools you can have.

Hope it helps,
CJ
 
Hi,

I want to check whether the record exist or not based on my query, so i'll
be using OleDbCommand.
What is the best way to check on a huge table ? I used to write like this in
VB6.0...

---------------------------------------------------
Public Function SaveOrUpdate() As Boolean
sSQL = "SELECT * FROM AdmAllergy WHERE " & _
" CompanyCode = " & mQuotedStr(mCompanyCode) & _
" AND BranchCode = " & mQuotedStr(mBranchCode) & _
" AND Code = " & mQuotedStr(sCode)
Set oRs = TmpAdoSet(sSQL)
With oRs
If .EOF And .BOF Then
.AddNew
.Fields("CompanyCode") = Trim(mCompanyCode)
.Fields("BranchCode") = Trim(mBranchCode)
.Fields("Code") = Trim(sCode)
.Fields("CreatedBy") = Trim(mUserId)
Else
.Fields("EditedBy") = Trim(mUserId)
.Fields("EditedDate") = Format(Now, "yyyy-mm-dd hh:mm:ss")
End If
.Fields("Name") = Trim(Name)
.UpdateBatch
.Close
End With
SaveOrUpdate = True
Set oRs = Nothing
End Function
---------------------------------------------------

So, how do i write in VB.Net ? Want to open check record exist or not. If
exist then update other fields
or else add new record. I prefer to use OleDbCommand.

Any Help ?

Regards
 
Back
Top