How to set up a sql adapter

Posted on 2006-05-18
Last Modified: 2010-04-23
I'm using 2003 and I would like some help setting up a sql data adapter.
Question by:sirbounty
    LVL 35

    Assisted Solution

    Dim conn As SqlConnection
            Dim ds As New DataSet
            Dim query As String

            query = "SELECT * FROM Table"
                conn = New SqlConnection("your connection string here")

                Dim da As SqlDataAdapter = New SqlDataAdapter(query, conn)
                ''fill dataset
            Catch ex As SqlException
                'Catch ex As SqlException
                Console.Write("SQL ERROR: " & ex.Message)
            Catch ex As Exception
                Console.Write("ERROR: " & ex.Message)
                If conn.State = ConnectionState.Open Then
                End If
            End Try
    LVL 6

    Accepted Solution

    Hi sirbounty,
    There are 3 steps to set the adapter

    define connnections
    define the queries for Data retrivals data update delete and insert
    define Dataadpter and assign the command to the appropriate daatadapter property

    example for select command

    private SqlConnection conn = new SqlConnection();
    conn.ConnectionString = ConfigurationSettings.AppSettings["ConnectionString"];
    private SqlCommand cmd = new SqlCommand();
    cmd.CommandText = "Select documentType from LastItemId";
    cmd.Connection = conn;
    private SqlDataAdapter da = new SqlDataAdapter();
    da.selectcommand = cmd;

    and now if u want to fill the dataset then

    DataSet ds = new Dataset();
    da.fill(ds, "MyTable");

    and after that u can assign the data to  datagrid

    grid.datasource = ds.tables[0];

    LVL 6

    Expert Comment

    The same way u can go for update delete and insert command

    da.UpdateCommand = updatecommand
    da.insertcommand = insertcommand
    da.deletecommand = deletecommand

    and u can call this 3 methods in one call


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    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 …
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    760 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

    9 Experts available now in Live!

    Get 1:1 Help Now