how to ADO in .Net

deulu

New member
Joined
Sep 11, 2006
Messages
3
Programming Experience
1-3
Hi
I am a VB coder and am starting lately to program with .net.

There is something i could do in VB that i don't know how in vb.net.

this is it:
VB.NET:
Global rs1 As ADODB.Recordset
 
 
MySelect = "select max(sequence) from table1 where fullid='" & FullID & "'"
 
     Set rs2 = New ADODB.Recordset
     rs2.Open MySelect, cn2
 
    If rs2.EOF Or IsNull(rs2(0)) Then
        sequence= 1
    Else
        sequence= rs2(0) + 1
    End If
 
and then insert statement
 
 
          With CMD1
             .CommandText = MyInsert
             .Execute
          End With

This code selects the maximum sequence and checks out if it is 1 or more. If more then adds it up by one using rs that refers to this max(sequence).

What i need to do is how can i refer to max(sequence) in VB.net. i need this piece of code implemented in VB.net ..do i use rs? and how?


pls, this is so urgent..
i'd appreciate any help.
thanks
 
You must learn and use ADO.NET. There is no such thing as a recordSet in ADO.NET.

What you can do though is import ADO 2.x object and then you can run this code through VB.NET.

Keep in mind ADO.NET is many times better than ADO 2.x.
 
I know that ADO.Net is much better than ADO 2.x that's why am trying to start programming with it. But the query i posted before has a code. In case i need to refrase that in VB.net, how could i do it? i need to write it in .Net. I don't mind if i use recordset or not, i only mind of how can i write this down in .Net.

Pls this is urgent.. Thank you
 
Last edited by a moderator:
Well here's an example that uses ADO.NET and a dataAdapter. It would be better to use a dataReader as its faster for this command. Keep in mind a dataReader is used as read-forward-only for records whereas the dataAdapter gives a memory representation of the database locally (use for updates etc).

VB.NET:
Imports System.Data.sqlclient

        Dim sqlCom As New SqlCommand()
        Dim sqlCon As New SqlConnection()
        Dim sqlDA As New SqlDataAdapter()
        Dim dTable As DataTable 'You can imagine this as your recordSet in ADO 2.x

        With sqlCom
            .Connection = sqlCon
            .CommandText = "select max(sequence) from table1 where fullid='" & FullID & "'"
        End With

        sqlCon.Open()

        sqlDA.SelectCommand = sqlCom
        sqlDA.Fill(dTable) 'Executes the command

        DataGridView1.DataSource = dTable.DefaultView 'Databind the grid with the results.
 
Last edited:
Thanks i see you have filled the datatable (dtable) with the selection, but what i wanted is how can i use this selection:
adding it up by 1.
You see in my example, i use rs1(0) . i fill it with the selected item and then add to it 1 : sequence = rs1(0) +1

I can't add to dtable a 1.

Thanks
 
Back
Top