Switching from ADO to ADO.NET example needed

R

Rick Lederman

I've been developing in VB6 & DAO for quite some time. I have figured out
how to use ADO (see the following code sample) but want to drop ADO and move
to ADO.NET. Can someone please point me to an article or book or re-do the
code below so I can move on. I have the MSDN article "ADO.NET and You"
which got me started, I have a good connection string but just can't figure
out how to get a single record, grab it's value, and update it if necessary.

Thanks!
Rick Lederman, (e-mail address removed), www.soaringsoftware.com

Dim cnFAMax As New ADODB.Connection

cnFAMax.Provider = "Microsoft.Jet.OLEDB.4.0;"

cnFAMax.CursorLocation = ADODB.CursorLocationEnum.adUseServer

cnFAMax.Open("Data Source=" & sCDatabaseName & "; Jet OLEDB:Database
Password=" & sMasterDatabasePassword & ";")

sSql.Remove(0, sSql.Length)

sSql.Append("SELECT PARAMETERS_.* FROM PARAMETERS_;")

Try

rsSearch.Open(sSql.ToString, cnFAMax,
ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)

Catch ex As Exception

MsgBox("The Recordset failed to open")

End Try

'MyOptions.PercentRemainingRed()

rsSearch.Find(("NAME_ = 'MyOptions.PercentRemainingRed'"))

If rsSearch.EOF = True Then

MyOptions.PercentRemainingRed = 30

rsSearch.AddNew()

rsSearch.Fields("NAME_").Value = "MyOptions.PercentRemainingRed"

rsSearch.Fields("VALUE_DOUBLE").Value = 30

rsSearch.Update()

Else

MyOptions.PercentRemainingRed = rsSearch.Fields("VALUE_DOUBLE").Value

End If

rsSearch.MoveFirst()

' Then I do another .Find to find the next appropriate record & test it's
value the same.



Thanks again!
 
M

Mahesh ChandraMouli

Hi,

Check these URL's you will get a fair idea of migrating
ADO to ADO.NET

http://www.developer.com/net/net/article.php/2228221
http://www.winnetmag.com/Article/ArticleID/21940/21940.htm
l

Read this book:
Pragmatic ADO.NET: Data Access for the Internet World



Regards
Mahesh ChandraMouli
Microsoft .NET MVP|MCAD (Charter Member)
-----Original Message-----
I've been developing in VB6 & DAO for quite some time. I have figured out
how to use ADO (see the following code sample) but want to drop ADO and move
to ADO.NET. Can someone please point me to an article or book or re-do the
code below so I can move on. I have the MSDN article "ADO.NET and You"
which got me started, I have a good connection string but just can't figure
out how to get a single record, grab it's value, and update it if necessary.

Thanks!
Rick Lederman, (e-mail address removed), www.soaringsoftware.com

Dim cnFAMax As New ADODB.Connection

cnFAMax.Provider = "Microsoft.Jet.OLEDB.4.0;"

cnFAMax.CursorLocation = ADODB.CursorLocationEnum.adUseServer

cnFAMax.Open("Data Source=" & sCDatabaseName & "; Jet OLEDB:Database
Password=" & sMasterDatabasePassword & ";")

sSql.Remove(0, sSql.Length)

sSql.Append("SELECT PARAMETERS_.* FROM PARAMETERS_;")

Try

rsSearch.Open(sSql.ToString, cnFAMax,
ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)

Catch ex As Exception

MsgBox("The Recordset failed to open")

End Try

'MyOptions.PercentRemainingRed()

rsSearch.Find(("NAME_
= 'MyOptions.PercentRemainingRed'"))
If rsSearch.EOF = True Then

MyOptions.PercentRemainingRed = 30

rsSearch.AddNew()

rsSearch.Fields("NAME_").Value
= "MyOptions.PercentRemainingRed"
 
W

William \(Bill\) Vaughn

My book ADO.NET and ADO Examples and Best Practices focuses on conversion
issues and should help.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
K

Kevin Yu [MSFT]

Hi Rick,

Here's an ADO.net sample application in MSDN. Hope it helps.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
R

Rick Lederman

Kevin,

Your post says "Here's and ADO.net sample" etc. but there is no link or
anything else in your post!

Concerning the other two posts. One recommends his book (Bill Vaughn),
which I find I already have! I've been reading it again for the last three
hours. It is quite clear how to bind a dataset to a control. However, I
want to grab a piece of data, assign it to a variable and update the data if
necessary. I also want to be able to detect if there are no records as a
result of a query, and then add a record of that data if none were there to
begin with, as in setting default parameters for a program. My original
post had some sample code to sort of explain what I'm trying to do in ADO.

Bill Vaughn's book may have the answer but after reading about 300 pages a
couple times tonight I still haven't figured it out although I have found a
couple tables that may lead me to a solution.

I'm giving up for this evening and attacking it again tomorrow as I have for
the last month or so.
 
K

Kevin Yu [MSFT]

Hi Rick,

Sorry that I forgot to paste the link in my last post. Here's an article
about ADO.NET for the ADO Programmers.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
ml/adonetprogmsdn.asp

And here's a sample application which implements some basic functions using
ADO .net

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconsampleapplication.asp

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
K

Kevin Yu [MSFT]

Hi Rick,

Sorry that I forgot to paste the link in my last post. Here's an article
about ADO.NET for the ADO Programmers.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
ml/adonetprogmsdn.asp

And here's a sample application which implements some basic functions using
ADO .net

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconsampleapplication.asp

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
W

William \(Bill\) Vaughn

Kevin, you need to upgrade your copy of Outlook Express. You've sent several
messages lately that have broken URLs due to the length of the path.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top