How to retrieve records from table(MS SQL Server) using VB.Net

Posted on 2006-05-17
Last Modified: 2011-10-03
Im a newbie VB.Net user.

I just want to ask how can i retrieve records from table/database (MS SQL Server).  (I'm already connected with the server)

Please complete the codes including the variables/Type. (SQL Statement please)
And if possible, can u give me a link on Tutorial.

Question by:rtdavid
    LVL 3

    Accepted Solution

    Hi There,

    Try this one, I assume you are familiar with SQL already..

    Dim conn As New SqlConnection(SQL_CONNECTION_STRING)
    Dim cmd As New SqlCommand("Select * from mytable where recordID > 100", conn)
    dim adp as new sqldataadapter(cmd)
    dim tbl as new datatable

    dim drow as datarow

    for each drow in tbl.rows"field1"))"field2"))"field3"))

    hope this helps



    Author Comment


       I got an errors :
          Type SqlConnection is not defined
          Type SqlCommand is not defined
          Type sqldataadapter is not defined

    LVL 6

    Expert Comment


    Imports System.Data.SqlClient

    at top of class

    Author Comment

    Thanks alot for helping...... by the way can u give me a link of site where i can get  a tutorial on VB.Net.???

    Thanks again.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Suggested Solutions

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now