Unable to save data
Unable to save data
Unable to save data
Unable to save data
Unable to save data
Unable to save data Unable to save data Unable to save data Unable to save data Unable to save data Unable to save data Unable to save data Unable to save data
Unable to save data Unable to save data
Unable to save data
Go Back  Xtreme Visual Basic Talk > > > Unable to save data


Reply
 
Thread Tools Display Modes
  #1  
Old 12-30-2015, 02:30 PM
QEDDave QEDDave is offline
Newcomer
 
Join Date: Jun 2010
Posts: 3
Default 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

Last edited by Flyguy; 12-31-2015 at 02:44 AM. Reason: Please start your own threads for asking questions and use the [code][/code] tags
Reply With Quote
  #2  
Old 01-05-2016, 09:28 AM
PlausiblyDamp's Avatar
PlausiblyDampUnable to save data PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,056
Default

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.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Unable to save data
Unable to save data
Unable to save data Unable to save data
Unable to save data
Unable to save data
Unable to save data Unable to save data Unable to save data Unable to save data Unable to save data Unable to save data Unable to save data
Unable to save data
Unable to save data
 
Unable to save data
Unable to save data
 
-->