rs.AdNew() equivelent in vb.net

K

Kevin R

This week I've begun to learn vb.net by re-writing an existing VB app. I'm
having a difficult time figuring how to add new records to an ADODB
recordset. How would I re-write the '.AddNew' statement in vb.net?

Thanks in advance!

Kevin
================
-----vb6
' Populate the local table
While Not rs.EOF

With rsLocal
.AddNew
!User_Login = rsSQL("User_Login")
!Current_Status = rsSQL("Current_Status")
.Update
End With

rs.MoveNext
Wend
================
-----vb.net
I get the build error in vb.net "Property 'Fields' is 'ReadOnly'. What is
the proper syntax to this: rsLocal!User_Login = rsSQL("User_Login")

' Reopen local table
sSQL = "Select * from tblStudentAdmissionsData"
rsLocal.Open(sSQL, cnLocalConnection, ADODB.CursorTypeEnum.adOpenDynamic,
ADODB.LockTypeEnum.adLockOptimistic)
With rsLocal
rsLocal.AddNew()
rsLocal!User_Login = rsSQL("User_Login")
 
K

Kevin R

Samuel,

Thanks for the reply. I don't know enough about .net to get this to
work so I'm looking at msdn to try to understand this.

Thanks!

Kevin
 
S

Samuel R. Neff

Here's a real code example, maybe it will help more..

' _dt is a DataTable..

Private Sub InitGrid()
Dim i As Integer
Dim r As DataRow
_dt.Columns.Add(New DataColumn("One"))
_dt.Columns.Add(New DataColumn("Two"))
For i = 0 To 9
r = _dt.NewRow
r(0) = i
r(1) = i ^ 2
_dt.Rows.Add(r)
Next

UltraGrid1.SetDataBinding(_dt, "")

End Sub
 
K

Kevin R

Thanks Samuel,

I figured out how to modify my existing code. My code works with the
following tweaks. It took awhile to find them!

vb6--------------------
With rsLocal
.AddNew
!User_Login = rsSQL("User_Login")
!Current_Status = rsSQL("Current_Status")
.Update
End With

..net-----------------------
With rsLocal
.AddNew
rsLocalFields("User_Login").Value = rsSQL("User_Login")
rsLocalFields("Current_Status").Value =
rsSQL("Current_Status")
.Update
End With


I was looking at your example an realized that I woul be designing the
recordset table structure in the code. Since I'm pulling the table
structure from the query I don't have to redefine the underlying structure.

I do realize I have a lot to learn!!!!!!!

Thanks for the replys!

Kevin
 
C

Chris, Master of All Things Insignificant

Kevin-

What is rsLocal in your code? It looks like you are using the old ADO
functionality. This isn't managed .net code. The ADO.NET way of doing
things doesn't have a recordset like you are use to thinking about it.
Instead it has a DataReader and a DataAdapter which returns the data. You
can use the DataAdapter to fill a datatable and then Samuel's way of doing
things applies. If you want to move to .Net you should look up using a the
DataReader/DataAdapter classes.

Hope it helps some.
Chris
 
C

Cor Ligthert

Kevin,

In my opinion is learning VBNet using a conversion not the best way to learn
it, you will for sure learn bad behaviour to keep things compatible.

As you saw direct from the post of the others that dotNet is almost
completly different than VB classic.

Although when busy you see a lot in common and that will help you to make a
quick start.

Have a look at GotDotnet quickstart. There are very simple samples in every
kind.

After those you can probably better update you existing program.
(This was my first expirience with dotNet as well by the way, however than
for ASPX)

http://samples.gotdotnet.com/quickstart/

Just my thought,

Cor
 
K

Kevin R

Thanks for the info Chris. I do want to learn this the correct way so I'll
begin reading up and following examples on using DataReader/DataAdapter
classes. I'm familiar with the 'old ADO functionality' for sure.......this
is all new!

Thanks all for the responses!

Kevin R
 

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