473,473 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

rs.AddNew in ado.net

'hi, this code is easy and straight forward in ADODB. if ADO.NET is easier
'and requires less code writing..., how do i write the same code...

rs.Open "SELECT * FROM tb_City WHERE name='Vancouver'", myConn, 3,4

if rs.Eof then
rs.AddNew
End if

rs("LastViewed")=Now()
rs.UpdateBatch()

' To keep in mind...
' I want to check if a vancouver exists, if not, add it, if yes, just update
' the record that is there.
Nov 18 '05 #1
4 1533
Tascien wrote:
'hi, this code is easy and straight forward in ADODB. if ADO.NET is
easier 'and requires less code writing..., how do i write the same
code...

rs.Open "SELECT * FROM tb_City WHERE name='Vancouver'", myConn, 3,4

if rs.Eof then
rs.AddNew
End if

rs("LastViewed")=Now()
rs.UpdateBatch()

' To keep in mind...
' I want to check if a vancouver exists, if not, add it, if yes, just
update ' the record that is there.


You could use a DataSet / DataAdapter as follows:

' Get the 'ABLEC' customer
SqlDataAdapter1.SelectCommand.Parameters("@Custome rID").Value = "ABLEC"
SqlDataAdapter1.Fill(DataSet1, "Customers")

' If we found the 'ALFKI' record
If DataSet1.Tables("Customers").Rows.Count > 0 Then
' Update the record
DataSet1.Tables("Customers").Rows(0)("ContactName" ) = "Carl Prothman"
Else
' Insert a new record
Dim newRow As DataRow = DataSet1.Tables("Customers").NewRow()
newRow("CustomerID") = "ABLEC"
newRow("CompanyName") = "Able Consulting, Inc."
DataSet1.Tables("Customers").Rows.Add(newRow)
End If
SqlDataAdapter1.Update(DataSet1)

Where SqlConnection, SqlDataAdapter1, and DataSet1 are objects
on the Form.

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP

Hire top-notch developers at
http://www.able-consulting.com
Nov 18 '05 #2
Who told you that ADO.NET would require less code? In some cases, this is
true, in many others it is not.

ADO.NET is a much more powerful object model than classic ADO. This
provides better performance and a wider variety of what can be done with
data. But, because there is so much more available, it may very well mean
that more code will need to be written.
"Tascien" <ta******@ecoaches.com> wrote in message
news:80**************************@posting.google.c om...
'hi, this code is easy and straight forward in ADODB. if ADO.NET is easier
'and requires less code writing..., how do i write the same code...

rs.Open "SELECT * FROM tb_City WHERE name='Vancouver'", myConn, 3,4

if rs.Eof then
rs.AddNew
End if

rs("LastViewed")=Now()
rs.UpdateBatch()

' To keep in mind...
' I want to check if a vancouver exists, if not, add it, if yes, just update ' the record that is there.

Nov 18 '05 #3
Thank you for your input. I am learning this 'brand new' language that
microsoft calls 'Visual Basic'.net but, it does not seem to work and
as easy as VB. So, you understand my pain!

But, i am getting the hang of it now, i hope i will get better.

T.
"Scott M." <s-***@BADSPAMsnet.net> wrote in message news:<#P**************@tk2msftngp13.phx.gbl>...
Who told you that ADO.NET would require less code? In some cases, this is
true, in many others it is not.

ADO.NET is a much more powerful object model than classic ADO. This
provides better performance and a wider variety of what can be done with
data. But, because there is so much more available, it may very well mean
that more code will need to be written.
"Tascien" <ta******@ecoaches.com> wrote in message
news:80**************************@posting.google.c om...
'hi, this code is easy and straight forward in ADODB. if ADO.NET is easier
'and requires less code writing..., how do i write the same code...

rs.Open "SELECT * FROM tb_City WHERE name='Vancouver'", myConn, 3,4

if rs.Eof then
rs.AddNew
End if

rs("LastViewed")=Now()
rs.UpdateBatch()

' To keep in mind...
' I want to check if a vancouver exists, if not, add it, if yes, just

update
' the record that is there.

Nov 18 '05 #4
I "feel your pain" as they say. The best advice I can give is not to try to
say to yourself "I used to do it this way so it must be done the same way in
..NET".
"Tascien" <ta******@ecoaches.com> wrote in message
news:80**************************@posting.google.c om...
Thank you for your input. I am learning this 'brand new' language that
microsoft calls 'Visual Basic'.net but, it does not seem to work and
as easy as VB. So, you understand my pain!

But, i am getting the hang of it now, i hope i will get better.

T.
"Scott M." <s-***@BADSPAMsnet.net> wrote in message

news:<#P**************@tk2msftngp13.phx.gbl>...
Who told you that ADO.NET would require less code? In some cases, this is true, in many others it is not.

ADO.NET is a much more powerful object model than classic ADO. This
provides better performance and a wider variety of what can be done with
data. But, because there is so much more available, it may very well mean that more code will need to be written.
"Tascien" <ta******@ecoaches.com> wrote in message
news:80**************************@posting.google.c om...
'hi, this code is easy and straight forward in ADODB. if ADO.NET is easier 'and requires less code writing..., how do i write the same code...

rs.Open "SELECT * FROM tb_City WHERE name='Vancouver'", myConn, 3,4

if rs.Eof then
rs.AddNew
End if

rs("LastViewed")=Now()
rs.UpdateBatch()

' To keep in mind...
' I want to check if a vancouver exists, if not, add it, if yes, just

update
' the record that is there.

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Jan van Veldhuizen | last post by:
I have an application which is running fine with MS SqlServer, but it should be working with Oracle as weel. At a lot of places we rely upon the ADO Recordset to return incremented identity...
2
by: Tim Marshall | last post by:
ODBC situation, Access 97, here is the code and I've marked where Access coughs up. The Access error message is 3027, can't update, database is read only. The Oracle table in question has a...
1
by: Jon Trelfa | last post by:
I have been fighting with this script for several days and I'm finally at the end of my rope. Here's the scenario: -I have to add an entry into 1 table, called "calendar" -I must retrieve the...
6
by: Aaron Smith | last post by:
I have a form, oddly enough the same one with the expression column that is giving me a headache, and on this form I have a dataset that has a couple of tables in it that are related. If I do a...
2
by: guy | last post by:
if i use Generics.AddNew how do I pass an object to the items constructor? I have a set of class all inheriting from a base class, all requiring one parameter on their constructor - the data...
2
by: pillmill | last post by:
I replaced AddNew statments with INSERT INTO, but am unable to write to the same tables. Foreign keys violations are the main errors. Why are these occuring ? Before: set rs3=...
8
by: MLH | last post by:
Here's a snippet from A97 HELP on AddNew... The record that was current before you used AddNew remains current. If you want to make the new record current, you can set the Bookmark property to...
5
by: amey.gupte | last post by:
Hi, I am using the AddNew function in VBA to populate my access table from data in excel. The following is the piece of code: With WriteRS .AddNew !column_Names(0) = "acctNo" !B = "CoName"...
1
by: teenagelcruise | last post by:
hi, i have a problem with my code which is i cannot update and addnew data into the database but i can delete the data.plz give me an idea.this is my code that i wrote. <html> <head> <meta...
0
nev
by: nev | last post by:
Have any of you encountered this? And how did you correct it? bs.addnew() automatically moves the position to the new record. But mine doesn't. I have 3 bindingsources in my program, all...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.