Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET Database and Reporting (http://www.xtremevbtalk.com/-net-database-and-reporting/)
-   -   Unable to save data (http://www.xtremevbtalk.com/-net-database-and-reporting/327998-unable-save-data.html)

QEDDave 12-30-2015 02:30 PM

Unable to save data
 
I can't get this to Save ... any ideas??

Code:

    Private Sub btnConsole_Click(sender As Object, e As EventArgs) Handles btnConsole.Click
        Dim ds As DataSet = New DataSet()
        Dim tblPicture As DataTable
        Dim tblNewPics As DataTable
        Dim tblPictureCount As Integer
        Dim i As Integer

        Dim conn As SqlConnection = New SqlConnection("Server=R850-PC\SQLEXPRESS2012;database=NewParts;Integrated Security=True;Persist Security Info=False")
        Dim da As SqlDataAdapter = New SqlDataAdapter("Select * from Picture Where IsNew = 1", conn)
        da.Fill(ds, "Picture")
        tblPicture = ds.Tables("Picture")
        tblPictureCount = tblPicture.Rows.Count
        tblPictureCount = tblPictureCount - 1

        'SOURCE Picture table to the screen.
        Console.WriteLine("Source Table tblPicture has " & tblPictureCount.ToString & " Rows")

        For i = 0 To tblPictureCount
            Console.WriteLine("Row(" & i.ToString & ") = " & tblPicture.Rows(i)(3))
        Next

        '********************* ADD TO NEW TABLE DATA **************************************************************************************

        Dim da2 As SqlDataAdapter = New SqlDataAdapter("Select * from Picture_Temp", conn)
        da2.Fill(ds, "Picture_Temp")
        tblNewPics = ds.Tables("Picture_Temp")
        tblNewPics = tblPicture.Clone

        For i = 0 To tblPictureCount
            tblNewPics.ImportRow(tblPicture.Rows(i))
            Dim dr2 As DataRow = tblNewPics.Rows(i)
            dr2.SetAdded()
        Next
        da2.Update(ds.Tables("Picture_Temp"))
        tblNewPics.AcceptChanges()

        '******************* DEBUG ... check new database table
        Console.WriteLine()
        Console.WriteLine("Destination TABLE has " & tblNewPics.ToString & " Rows")
        For i = 0 To tblPictureCount
            Console.WriteLine("Row(" & i.ToString & ") = " & tblNewPics.Rows(i)(3))
        Next
        Console.WriteLine("RowState = " & tblNewPics.Rows(i - 1).RowState.ToString)
        Console.ReadLine()

        txtMessages.Text = "Done"

    End Sub


PlausiblyDamp 01-05-2016 09:28 AM

Is it throwing any exceptions or just not updating the database?

Without trying the code itself the bit
Code:

tblNewPics = ds.Tables("Picture_Temp")
tblNewPics = tblPicture.Clone

For i = 0 To tblPictureCount
    tblNewPics.ImportRow(tblPicture.Rows(i))
    Dim dr2 As DataRow = tblNewPics.Rows(i)
    dr2.SetAdded()
Next

looks like it might be the problem as you seem to be getting the contents of the Picture_Temp table and then discarding the results and replacing them with a copy of the Pictures table.


All times are GMT -6. The time now is 11:53 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.