Using .net 2.0 to insert a single row of data

Posted on 2006-03-28
Last Modified: 2010-04-23
I need to add a row of data to a table. In my attempt below I receive an error message saying that I need a valid insertcommand. However, even if this would work, it looks a bit inefficient. Also, what I want to do is to add ONE row of data as efficient as possible and avoid the use of sql. (i.e. insert into test (test1,test2) values ("text1","text2")...)

        Dim sqlConn As New System.Data.SqlClient.SqlConnection(myConnection)
        Dim da As New SqlClient.SqlDataAdapter("Select * from Test", sqlConn)
        Dim ds As New DataSet

        da.AcceptChangesDuringFill = True
        da.Fill(ds, "Test")

        Dim r As DataRow = ds.Tables("Test").NewRow()
        r("Test1") = "text1"
        r("Test2") = "text2"


        da.Update(ds, "Test")

Question by:Contestoas
    1 Comment
    LVL 62

    Accepted Solution

    Hi Contestoas;

    Try adding this line of code after you create the SqlDataAdapter.

    Dim cb As SqlCommandBuilder = New SqlCommandBuilder(da)


    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    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…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    746 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

    18 Experts available now in Live!

    Get 1:1 Help Now