Click here to Skip to main content
15,867,921 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I've tried many different ways to get this to work, from manually setting my dataadapter sql statements, auto generating them, and I even tried make my own update method in the dataadapter. It does update the dataset, but does not write to the database. I also checked the row state before it's updated, and it was modified. I'm at a loss on this, any help is appreciated!

VB
Imports System.Data.SqlClient
Imports System.Data
Imports System.Linq
Public Class Form1
    Dim con As New SqlConnection(My.Settings.PUBSConnectionString)
    Dim da As New SqlDataAdapter("select * from titles", My.Settings.PUBSConnectionString)
    Dim sql As String = "select * from titles"
    Dim cb As New SqlCommandBuilder(da)
    ' Dim da As New PUBSDataSetTableAdapters.titlesTableAdapter
    Dim ds As New DataSet
    Dim dt As New DataTable
    Dim dr As DataRow = Nothing



    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        da.UpdateCommand = cb.GetUpdateCommand
        da.InsertCommand = cb.GetInsertCommand
        da.Fill(ds, "titles")
        DataGridView1.DataSource = ds
        DataGridView1.DataMember = "titles"



        ' da.UpdateCommand.CommandText = "UPDATE [dbo].[titles] SET [title] = @title, [type] = 'type', [pub_id] = @pub_id, [price] = @price, [advance] = @advance, [royalty] = @royalty, [ytd_sales] = @ytd_sales, [notes] = @notes, [pubdate] = getdate() WHERE (([title_id] = @title_id))"

        'da.UpdateCommand = New SqlCommandBuilder(da).GetUpdateCommand
        'da.UpdateCommand.CommandText = "UPDATE [titles] SET [title] = @p2, [type] = @p3, [pub_id] = @p4, [price] = @p5, [advance] = @p6, [royalty] = @p7, [ytd_sales] = @p8, [notes] = @p9, [pubdate] = @p10 WHERE [title_id] = @p1"
        'da.InsertCommand = New SqlCommandBuilder(da).GetInsertCommand
        'da.DeleteCommand = New SqlCommandBuilder(da).GetDeleteCommand
        'da.InsertCommand.CommandText = "INSERT INTO [titles] ([[type], [pub_id], [price], [advance], [royalty], [ytd_sales], [notes], [pubdate]) VALUES (@p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10)"

        'dt = ds.titles.Copy
        'dt.Rows.Clear()


        DataGridView1.RowsDefaultCellStyle.BackColor = Color.LightCyan
        DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGray
    End Sub


    Private Sub SaveChangesToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SaveChangesToolStripMenuItem.Click
        Dim col As New DataColumn

        DataGridView1.EndEdit()
        ds.EndInit()
        da.Update(ds.Tables("titles"))
End Sub
Posted
Comments
ZurdoDev 16-Nov-13 21:22pm    
There's no code to write it to the database.
member 8888995 16-Nov-13 23:49pm    
where you are updating to database?
drummer07 17-Nov-13 1:02am    
The update method is supposed to write to the database, passing it the table inside of the dataset which has the modified values.
dbrenth 26-Nov-13 15:51pm    
Have you tried catching the Adpater's RowUpdated event and seeing what messages appear there?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900