Insert record not adding VB2005/SQL database

aspnovice
12-10-2005, 10:48 PM
Hi Guys,

This is a follow up from my last post but is a different issue so I have started a new thread.

I have been following a tutorial in a book Vb 2005 Jumpstart Ch 4

Anyway I have followed the books code exactly and the program runs.

It connects to Amazons web service and allows the user to search and display books, the application also allows the user to save the titles that they wish by clicking an Add Title button, when the user does this the current focus title is saved to the database and can be viewed off line.

When I hit the add title the record gets saved as I can hit the catalog button which opens a new form with a datagrid that has all the titles I just saved in it!! GREAT!!

But when I close the app and run it again the catalog is gone?? back to no records again?

Now ive never worked with SQL databases before and this is me just having a go at .Net so I have no idea whats wrong or where to look.

Here is the code I have that inserts the data when the Add Title button is clicked


Public Sub AddTitle()
Try
'---get the book cover image as a byte array---
Dim ms As New System.IO.MemoryStream()
picCover.Image.Save(ms, picCover.Image.RawFormat)
Dim coverimage() As Byte = ms.GetBuffer
ms.Close()
'Double.Parse(txtPrice.Text)
txtPrice.Text = Strings.Replace(txtPrice.Text, "$", "")
txtPrice.Text = Strings.Replace(txtPrice.Text, "£", "")
'---add the new title to the database---
TitlesTableAdapter.Insert(lblISBN.Text, _
txtTitle.Text, txtAuthors.Text, _
txtPublisher.Text, txtPrice.Text, coverimage)


ToolStripStatusLabel1.Text += " - Added"
Catch ex As Exception
DisplayError("Error adding title. - " & ex.Message)
End Try
End Sub




I thought adding something like this would work, but alas it is not!!


TitlesTableAdapter.Update(LibraryDataSet)



Any help is greatly appreciated.
Thanks again
colin

RD Frame
12-11-2005, 02:22 AM
Sorry buddy, and wish I could help, but I've been stuck on this problem for the past three days. I've spent probably 16 hours, read through the documentation time and time again, and have tried every possible variation I can think of, and always end up with the same results. Just like you have, the data gets inserted into the database, but never commits / saves / updates.

When I figure it out, I'll make sure to let you know though.

Matt

aspnovice
12-11-2005, 02:53 AM
Sorry buddy, and wish I could help, but I've been stuck on this problem for the past three days. I've spent probably 16 hours, read through the documentation time and time again, and have tried every possible variation I can think of, and always end up with the same results. Just like you have, the data gets inserted into the database, but never commits / saves / updates.

When I figure it out, I'll make sure to let you know though.

Matt

Thanks Matt,

Im glad im not the only one!! Are you using the same Oriely Vb 2005 Jumpstart book?

I wrote to the author as there was an email addy on the website :huh: and the reply I got was "It works here" Not a lot of help!! Puts you off buying Oriley books again.

RD Frame
12-11-2005, 08:25 AM
Ahh, I finally figured it out! Christ, what a gong show that became. In the Solution Explorer, click on your database file, then go down to the Properties. One of the fields there is "Copy to Output Directory". Make sure this is set to "Copy if newer". Then restart your application twice (it'll copy the database file again the first time), and that's it. It should work fine after that. :)

Matt

aspnovice
12-11-2005, 04:09 PM
Ahh, I finally figured it out! Christ, what a gong show that became. In the Solution Explorer, click on your database file, then go down to the Properties. One of the fields there is "Copy to Output Directory". Make sure this is set to "Copy if newer". Then restart your application twice (it'll copy the database file again the first time), and that's it. It should work fine after that. :)

Matt

WOW!!! How easy was that!!

How did you figure that out? Is that an SQL database property that we just set or is that a VS setting that needs to be put on any database?

Thanks again M8ty
Regards

RD Frame
12-11-2005, 04:43 PM
Well, there was one thread on the MSDN forums that helped out, plus I played around a little bit myself. It's not 100% yet, and we're pretty sure it's a bug now, unless we're doing something wrong. What I said will work fine, but just don't ever access the Database Explorer. The rows will be inserted into your database just fine, but right when you do anything in the Database Explorer, your database file will be overwritten again for some reason, and you'll be left with no data again.

There's a decent sized thread going on about this, and the ADO.NET Program Manager is actively involved, so hopefully we'll have a good reply within the next couple days. Thread is at:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=69953&SiteID=1&PageID=1

Alfetta159
06-27-2009, 01:06 PM
Thank you.

(!)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum