Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

emergency...ADO.NET

is there any way we can avoid use of data adapet and dataset to wprk with database. can we do programming like we did in ado in vb6 usinf adodb.connecyion string and adodb.recordset. can we also populate the combo box and data grib without adodataadapter and dataset??

Comments

  • danimr2k5danimr2k5 Member Posts: 1
    : is there any way we can avoid use of data adapet and dataset to wprk with database. can we do programming like we did in ado in vb6 usinf adodb.connecyion string and adodb.recordset. can we also populate the combo box and data grib without adodataadapter and dataset??
    :


    Hi
    i usually don't use the data adapter and i populate manually the controls of the form.
    I send a little source code that show how to print out in the console the list of a patients of a SQLServer Database.
    I hope you understand it.

    --------------Begin of Code---------------------

    Imports System.Data.SqlClient

    Module ListPatients

    Sub Main()
    'Show the patients in the Database
    'SqlServer SQLEXPRESS
    'Database MEDS
    'User sa
    'Password pass
    'Table PATIENTS
    'Fields NAME, SURNAME
    Dim conn As New SqlConnection("User Id=sa;Pwd=pass;Data Source=SQLEXPRESS;database=MEDS")
    Dim command As New SqlCommand
    Dim reader As SqlDataReader = Nothing

    'Open the connection
    Try
    conn.Open()
    Catch ex As Exception
    Console.WriteLine("Error Connecting to database")
    Exit Sub
    End Try

    'Query to the database
    command.Connection = conn
    command.CommandText = "SELECT NAME, SURNAME FROM PACIENTE"
    Try
    reader = command.ExecuteReader()
    Catch ex As Exception
    Console.WriteLine("Error executing Query")
    Exit Sub
    End Try

    'Print out the result
    While reader.Read()
    Console.WriteLine("Patient: " + reader("NAME") + " " + reader("SURNAME"))
    End While
    reader.Close()
    conn.Close()
    End Sub

    End Module
    ----------------------End of Code--------------------------

Sign In or Register to comment.