Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is ADO.Net the same as ADO 2.7? 1

Status
Not open for further replies.

FoxT2

MIS
Joined
Oct 3, 2003
Messages
143
Location
US
Hi,

When I setup my ADO connection like this...

Dim DBConnect As New ADODB.Connection
Dim A As New ADODB.Recordset
Dim B As New ADODB.Recordset
With DBConnect
If .State = ADODB.ObjectStateEnum.adStateOpen Then .Close()
.Open("MyTable","MySQLstring",blah,blah,blah)
End With

with the ADODB(2.7) reference added to my project am I using ADO.net?

FoxT
 
nope you are still using adodb

for ado.net it would look like this

dim con as new system.oledbclient.oledbconnection
dim adp as new system.oledbclient.oledbdataadapter
....
dim ds as new dataset

for connection to sql-server you should use

system.sqlclient.sqlconnection
...

Christiaan Baes
Belgium
"What a wonderfull world" - Louis armstrong
 
Thanks Chrissie,

Any chance you could help me with this code. I am not quite understanding this yet.
****************
Imports System.Data.SqlClient

Public Class Form1
Inherits System.Windows.Forms.Form
*Next 2 lines do not work*
Dim DBconnect As New System.oledbclient.oledbconnection
Dim DBadp As New System.oledbclient.oledbdataadapter
Dim A As New DataSet
Dim B As New DataSet

*What to do with rest of code here?*

With DBConnect
If .State = ADODB.ObjectStateEnum.adStateOpen Then .Close()
.Open("MyDatabase","MySQLstring",blah,blah,blah)
End With

With A
If .State = ADODB.ObjectStateEnum.adStateOpen Then .Close()
.Open("select * from MyTable order by id", DBConnect, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)
End With
***************

Thanks,

FoxT


 
this should work
dont mix sqlclient with oledbclient

Code:
Imports System.Data.SqlClient

Public Class Form1
    Inherits System.Windows.Forms.Form
*Next 2 lines do not work*
    Dim DBconnect As New sqlconnection
    Dim DBadp As New sqldataadapter
    Dim dbcom as new sqlcommand
    Dim A As New DataSet
    Dim B As New DataSet

*What to do with rest of code here?*

If DBconnect.State = ConnectionState.Closed Then
            DBconnect.ConnectionString = "workstation id=" & SQLservername & ";integrated security=SSPI;packet size=4096;data source=" & SQLservername & ";persist security info=False;initial catalog=" & Databasename
            DBconnect.Open()
        End If
        
   dbcom.Connection = DBconnect 
   DBadp.SelectCommand = dbcom 
   dbcom.commandtext = "select * from MyTable order by id"
   dbadp.fill(a,"table")
   textbox1.text = a.tables(0).row(0).item(0)

Christiaan Baes
Belgium
"What a wonderfull world" - Louis armstrong
 
sorry that should have read
'If you still wish to use ADODB'
 
Chrissie,

Anyway you could show me that same example code but only using ADO.net instead of SQLclient? Also, can SQLclient perform tasks on recordsets like ADO.

Example of ADO task...

If Not A.BOF Then A.MovePrevious()
If A.BOF Then
Beep()
A.MoveFirst()
End If
refreshfields()


FoxT
 
same in ado.net

Code:
Imports System.Data.oledb

Public Class Form1
    Inherits System.Windows.Forms.Form
*Next 2 lines do not work*
    Dim DBconnect As New oledbconnection
    Dim DBadp As New oledbdataadapter
    Dim dbcom as new oledbcommand
    Dim A As New DataSet
    Dim B As New DataSet

*What to do with rest of code here?*

If DBconnect.State = ConnectionState.Closed Then
            DBconnect.ConnectionString = "connectionstring here"
            DBconnect.Open()
        End If
        
   dbcom.Connection = DBconnect 
   DBadp.SelectCommand = dbcom 
   dbcom.commandtext = "select * from MyTable order by id"
   dbadp.fill(a,"table")
   textbox1.text = a.tables(0).row(0).item(0)

ado.net does not use recordset it uses datasets

Code:
dim inttemp as integer
for inttemp = 0 to a.tables(0).rows.count -1
  textbox1.text &= a.tables(0).rows(inttemp).item(0)
next

Christiaan Baes
Belgium
"What a wonderfull world" - Louis armstrong
 
ah finaly a star, that makes my day.

Christiaan Baes
Belgium
"What a wonderfull world" - Louis armstrong
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top