Advertisement

06.03.2008 at 09:17AM PDT, ID: 23453714
[x]
Attachment Details

Not able to update sql database after deleting rows

Asked by mark_norge in .NET, Visual Basic Programming, SQL Server 2005

Tags: visual basic .net

Hi Experts,
I have a visual basic 2005 application connected to SQL database.

When adding a row to the datatable, I do not give it a primairy key number. After the update command the row still does not have a primairy key number, but after closing and starting the application the primairy key number is shown in the datatable.

If I add a row and immediately delete the same row (so not close and start the application in between), but do use the update command the I get an DB concurrency error with the second update (processing the delete or the row.

I have been trying to solve this trying several codes but do not seem to get anywere. I tried to perform update command after each change I make in the datatable, using different ways to setup the updatecommand, use insert, update and delete commands; nothing.
 
I use several table and all tables have an own dataadapter. Below the code I use in the class form1, load event form1 and the code I use when closing the application for two or the tables. All tables in the database have a primairy key and index.

If someone has a solution, please... I am looking for a breakthrough after 8 hours :-)Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
Public Class Form1
 
Dim ds As DataSet
    Dim daBookings, daASNs As SqlDataAdapter
    Dim cb As SqlCommandBuilder
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        ds = New DataSet()
        Dim con As New SqlConnection()
        con.ConnectionString = "Data Source=CLIENT165\SQLEXPRESS;DataBase=c:\Visual Studio 2005\Projects\GreenVesselTally\GreenVesselTally\GreenVesselTally.mdf;uid=norge;pwd=boris;Trusted_Connection=True"
 
        daBookings = New SqlDataAdapter("SELECT * FROM Bookings", con)
        daASNs = New SqlDataAdapter("SELECT * FROM ASNs", con)
 
        daBookings.Fill(ds, "Bookings")
        daASNs.Fill(ds, "ASNs")
 
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
 
        Dim Rows As Integer
 
        cb = New SqlCommandBuilder(daBookings)
        cb.GetUpdateCommand()
        cb.GetDeleteCommand()
        Rows = daBookings.Update(ds.Tables("Bookings"))
 
 
        cb = New SqlCommandBuilder(daASNs)
        cb.GetUpdateCommand()
        Rows = daASNs.Update(ds.Tables("ASNs"))
[+][-]06.04.2008 at 02:36AM PDT, ID: 21708264

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.04.2008 at 02:38AM PDT, ID: 21708272

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.04.2008 at 03:31AM PDT, ID: 21708537

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.04.2008 at 03:44AM PDT, ID: 21708617

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .NET, Visual Basic Programming, SQL Server 2005
Tags: visual basic .net
Sign Up Now!
Solution Provided By: Dhaest
Participating Experts: 1
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628