By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,558 Members | 1,699 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,558 IT Pros & Developers. It's quick & easy.

How to check Eof in VB.Net ?

P: n/a

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
Nov 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a

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
=====================
Nov 20 '05 #2

P: n/a
Cor
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
Nov 20 '05 #3

P: n/a
Thanks cor,
i've done that. desperately waiting for an answer

Regards

"Cor" <no*@non.com> wrote in message
news:3f**********************@reader22.wxs.nl...
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

Nov 20 '05 #4

P: n/a
try desperately setting your system clock back to normal time.
"ItsMe" <it*******@yahoo.com> wrote in message
news:OM**************@TK2MSFTNGP09.phx.gbl...
Thanks cor,
i've done that. desperately waiting for an answer

Regards

"Cor" <no*@non.com> wrote in message
news:3f**********************@reader22.wxs.nl...
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


Nov 20 '05 #5

P: n/a
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.

"Daniel Bass" <da********@NOSPAMpostmaster.co.uk> wrote in message
news:OD**************@TK2MSFTNGP09.phx.gbl...
try desperately setting your system clock back to normal time.
"ItsMe" <it*******@yahoo.com> wrote in message
news:OM**************@TK2MSFTNGP09.phx.gbl...
Thanks cor,
i've done that. desperately waiting for an answer

Regards

"Cor" <no*@non.com> wrote in message
news:3f**********************@reader22.wxs.nl...
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


Nov 20 '05 #6

P: n/a
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
"ItsMe" <it*******@yahoo.com> wrote in message
news:OM**************@TK2MSFTNGP09.phx.gbl...
Thanks cor,
i've done that. desperately waiting for an answer

Regards

"Cor" <no*@non.com> wrote in message
news:3f**********************@reader22.wxs.nl...
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


Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.