Updating Database from DataSet

Posted by clawson on Stack Overflow See other posts from Stack Overflow or by clawson
Published on 2010-04-27T02:11:14Z Indexed on 2010/04/27 2:13 UTC
Read the original article Hit count: 446

Filed under:
|

I am having trouble updating my Database from my code using a DataSet. I'm using SQL Server 2008 and Visual Studio 2008. Here is what I've done so far.

I have created a table in SQL Server called MyTable which has two columns: id nchar(10), and name nchar(50).

I have then created a datasource in my VB.net project that consists of this table using the dataset wizard and called this dataset MyDataSet.

I run the following code on a button click:

    Try
        Dim myDataSet As New MyDataSet
        Dim newRow As MyDataSet.MyTableRow = myDataSet.MyTable.NewMyTableRow
        newRow.id = "1"
        newRow.name = "Alpha"
        myDataSet.MyTable.AddMyTableRow(newRow)
        myDataSet.AcceptChanges()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

when I run this and check the rows in SQL Server it returns 0 rows

What have I missed? How can I add these rows / save changes in a dataset to the database? I have seen other examples that use a TableAdapter but I don't think I want to do this, I think I should be able to achieve this just using a DataSet. Am I mistaken?

Help is greatly appreciated!

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about .NET