Wrox Programmer Forums
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 22nd, 2010, 03:08 PM
Authorized User
 
Join Date: Dec 2006
Posts: 43
Thanks: 4
Thanked 0 Times in 0 Posts
Send a message via MSN to Yasho
Talking Error when updating table

I have one table which i update from 2 different subs having the same command syntex with different values. With first sub the update works fine but with 2nd sub the update changes the table but give an error.[Error:Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints]

After googling it and exhausting all online resources, read thru some solutions i am still having the problem. Though I think deleting and recreating dataadapter and dataset would not make a difference, I have deleted and recreated both 3 times. Here is the code and please point out my "foolishness".

I have made it working for me without error (without knowing the side effects of my act) by setting Enforce Constraints property of dataset to False. Please advise me

first sub (this update works fine)
Code:
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand
Try
conScheduler.Open()
With cmd
.Connection = conScheduler
.CommandType = CommandType.Text
.CommandText = "UPDATE tblcrew SET Active = '" & "Yes" & "' " & " WHERE firstName ='" & txtFname.Text & "' AND lastname ='" & txtLName.Text & "'"
.ExecuteNonQuery()
.CommandText = "UPDATE tblcrew SET StartDate = '" & "0" & "' " & " WHERE firstName ='" & txtFname.Text & "' AND lastname ='" & txtLName.Text & "'"
.ExecuteNonQuery()
.CommandText = "UPDATE tblcrew SET EndDate = '" & "0" & "' " & " WHERE firstName ='" & txtFname.Text & "' AND lastname ='" & txtLName.Text & "'"
.ExecuteNonQuery()
EndWith
Catch ex As Exception
MessageBox.Show(ex.Message, ex.GetType.ToString)
ExitSub
EndTry
conScheduler.Close()
2nd sub (this gives error)
Code:
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand
Try
conScheduler.Open()
With cmd
.Connection = conScheduler
.CommandType = CommandType.Text
.CommandText = "UPDATE tblcrew SET Active = '" & "NO" & "' " & " WHERE crewID ='" & txtID.Text & "'"
.ExecuteNonQuery()
.CommandText = "UPDATE tblcrew SET StartDate = '" & "mydate1" & "' " & "WHERE crewID ='" & txtID.Text & "'"
.ExecuteNonQuery()
.CommandText = "UPDATE tblcrew SET EndDate = '" & "mydate3" & "' " & "WHERE crewID ='" & txtID.Text & "'"
.ExecuteNonQuery()
EndWith
 
Catch ex As Exception
MessageBox.Show(ex.Message, ex.GetType.ToString)
ExitSub
EndTry
conScheduler.Close()
__________________
yvk

Last edited by Yasho; October 22nd, 2010 at 06:00 PM.. Reason: adding more info





Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating one table with data from another table dirtdog22 Access VBA 1 January 21st, 2008 04:41 PM
Updating Table gregalb SQL Server 2000 1 June 2nd, 2007 04:39 PM
Updating table every now and then rtr1900 Classic ASP Databases 2 December 2nd, 2005 03:12 AM
Updating table Hudson40 Access VBA 6 March 23rd, 2005 12:07 PM
updating table markhardiman Classic ASP Databases 2 September 29th, 2004 12:35 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.