Luddites ! ; forward into the past ! (ADO/DAO)

B

barret bonden

Not needing disconnected data, and still somewhat fluent in DAO/ADO I've
played with both in .NET. Can't seem to be able to add a record; too much of
the syntax seems to have been OOP'ed (haven't posted my attempts here , as
they don't work - but below is the flavor of the thing as it stands

Data pops up fine in the textbox and movenext, etc work fine. (hope I'm in
the right newsgroup; if not please direct me -this is as close as I could
find)

Anyone know how to add a record ?

Imports System.Data
Imports System.Data.OleDb
Imports ADODB


Public Class Form1
Public conn As New ADODB.Connection
Public rs As New ADODB.Recordset

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim cs1 As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\test.mdb;"
' Dim Conn As New ADODB.Connection
' Dim rs As New ADODB.Recordset
Conn.Provider = cs1
Conn.Open(cs1, "", "", -1)
Dim sql As String
sql = "select * from test"
rs.Open(sql, cs1, ADODB.CursorTypeEnum.adOpenStatic,
ADODB.LockTypeEnum.adLockBatchOptimistic, 1)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
rs.MoveFirst()
Dim v1 As String
v1 = rs.Fields.Item(1).Value
TextBox1.Text = v1
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
rs.MoveNext()
Dim v1 As String
v1 = rs.Fields.Item(1).Value
TextBox1.Text = v1

end sub
 
C

Cowboy \(Gregory A. Beamer\)

In most fantasy stories, there is some harbinger of doom. I am the harbinger
of doom for those who continue to try to use traditional ADO with .NET. ;-)

ADO is COM based and causes a lot of interop to occur to get things done.
This is both error-prone and destroys performance. It is not impossible to
use with what you are attempting to do, but it is slow and clunky and hard
to debug when there are problems.

Disconnected data is certainly one reason to go to ADO.NET, but it was part
of a package with the rest of the .NET Framework, and not an independent
reason to get classicVBers to use ADO.NET with their apps.

My suggestion is take the step to make the paradigm shift. If it is hard to
do keeping the VB syntax, switch languages. It does not have to be a
permanent shift, just long enough to change paradigms.

If you want to continue down this road, ADO and ADO.NET work similarly with
adding a record, if you mean adding a record to the database and not to the
recordset. You gather the information and fire off a command object with
data in question. With ADO.NET, there are a lot of helper bits that will
allow you to simply call Update() and it will then create the Command object
behind the scenes for you. But no matter how you stack things, you will
eventually get to a command object.

Personally, I would pick up a book on ADO.NET, or read Dino Esposito's
articles, as the ADO.NET method is much easier.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Blog:
http://feeds.feedburner.com/GregoryBeamer

*********************************************
| Think outside the box |
*********************************************
 
G

gerry

I think its time to take a look at some documentation, every ADO.NET
doc/manual/book will have something like this on page 2 ;-)

a simple snippet, sorry c# - easy enough to convert :



string connectionString = "...";
string commandString="INSERT INTO [sometable] (id,name) VALUES (@ID,@NAME)";

using ( SqlConnection con = new SqlConnection(connectionString) )
{
using (SqlCommand cmd = new SqlCommand( con , cmdString ) )
{
cmd.Parameters.AddWithValue("@ID",name);
cmd.Parameters.AddWithValue("@NAME",name);
cmd.ExecuteNonQuery();
}
}
 
S

sloan

Using ADO in 2001/2002 when DotNet first came out, and you upconverted a
project...might have been kinda acceptable.

But in 2009.........its way past due to be properly converted.
 
W

William Vaughn \(MVP\)

Many others feel your pain--you're not alone. When ADO.NET was first
introduced, I too wanted to leverage my COM-based ADO (ADOc) skills and try
to help the developer community transition to ADO.NET. To this end I wrote a
book that addresses the issues developers face when migrating to ADO.NET
from ADOc. The result: "ADO and ADO.NET Best Practices for Visual Basic
Developers". This walks through the process of converting ADOc applications
to ADO.NET. While it's a bit dated now (nearly a decade later) it still
helps "classic" developers migrate their skills to ADO.NET. It shows how to
build server-side cursors and do the things developers did in the "olden"
days as well as how to leverage the advancements and "improvements"
Microsoft has provided. My latest book takes up where the ADO BP book takes
off and discusses how to use TableAdapters and a lot more sophisticated
coding practices.

hth

--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)
http://betav.com http://betav.com/blog/billva
____________________________________________________________________________________________
 

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

Top