PC Review


Reply
Thread Tools Rate Thread

3 table Access Database using vb.Net Problems with UPDATE and INSERT commands

 
 
jay B via DotNetMonster.com
Guest
Posts: n/a
 
      10th Jun 2005
BOOKINGS has a Primary key: Number. Two Foreign keys: UCI (link to
CUSTOMERS) & Code (link to HOLIDAYS).

HOLIDAYS has a Primary Key: Code.

The Database has one-to-many Relationships with Referential Integrity and
checked cascade UPDATE and DELETE (The many relationship for both links
being on the BOOKINGS table).

I have designed a GUI using vb.NET (Visual Studio) The connection to the
Database is via Microsoft Jet 4.0 OLE DB Provider and I have got the
following Datasets to work on both the CUSTOMERS and HOLIDAYS tables:
SELECT, INSERT, DELETE, UPDATE records. On coming to the BOOKINGS table
(which appears to be an INNER JOIN) I've got the SELECT and DELETE records
to work, but I'm having major problems getting the INSERT and UPDATE to
work. View the coding below:



'UPDATE BOOKING RECORD

Private Sub btnUpdateB_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdateB.Click

If MessageBox.Show("Do you wish to update the Booking record",
"Clear", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) =
DialogResult.Yes Then
End If

Try
OleDbConnection1.Open()
Dim command As String

'set up an SQL update

command = "UPDATE BOOKINGS SET Number = '" & txtNumber.Text _
& "', " & "UCI = '" & txtUCI.Text _
& "', " & "Code = '" & txtCode.Text _
& "', " & "Date = '" & txtDate.Text _
& "', " & "Adult = '" & txtAdult.Text _
& "', " & "Child = '" & txtChild.Text _
& "', " & "Deposit = '" & txtDeposit.Text _
& "', " & "Balance = '" & txtBalance.Text _
& "', " & "Cost = '" & txtCost.Text _
& "' WHERE Number = '" & txtNumber.Text & "'"

OleDbDataAdapter4.UpdateCommand.CommandText = command
lblSQL.Text = command

'do the update
OleDbDataAdapter4.UpdateCommand.ExecuteNonQuery()
Catch exceptionObject As Exception
MessageBox.Show(exceptionObject.Message)
Finally
OleDbConnection1.Close()
End Try
End Sub



'INSERT BOOKING RECORD
Private Sub btnInsertB_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnInsertB.Click

If MessageBox.Show("Do you wish to insert a new Booking Record",
"Insert", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) =
DialogResult.Yes Then
End If

Try
OleDbConnection1.Open()
Dim command As String
'set up an SQL insert
command = "INSERT INTO BOOKINGS(Number, Date, Adult, Child,
Deposit, Balance, Cost )" _
& " values('" & txtNumber.Text & "', '" & txtDate.Text &
"','" & txtAdult.Text & "','" & txtChild.Text & "','" & txtDeposit.Text &
"','" & txtBalance.Text & "','" & txtCost.Text & "')"


OleDbDataAdapter4.InsertCommand.CommandText = command
lblSQL.Text = command

' do the insert
OleDbDataAdapter4.InsertCommand.ExecuteNonQuery()
Catch exceptionObject As Exception
MessageBox.Show(exceptionObject.Message)
Finally
OleDbConnection1.Close()
End Try
End Sub


'DELETE BOOKING RECORD
Private Sub btnDeleteB_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDeleteB.Click

If MessageBox.Show("Do you wish to delete Booking Record",
"Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) =
DialogResult.Yes Then
End If

Try
OleDbConnection1.Open()
Dim command As String

'set up an SQL delete
command = "DELETE FROM BOOKINGS WHERE Number = '" &
txtNumber.Text & "';"

OleDbDataAdapter4.DeleteCommand.CommandText = command
lblSQL.Text = command

'do the delete
OleDbDataAdapter4.DeleteCommand.ExecuteNonQuery()
Catch exceptionObject As Exception
MessageBox.Show(exceptionObject.Message)
Finally
OleDbConnection1.Close()
End Try
End Sub


I think I need either ALTER type commands or CASCADING type commands on
each???

Will any changes need to be made to the OleDbDataAdaptor or the
OleDbDataConnection via Visual Studio?

Can anybody help? I’m in despair (;-((
--
Jay B
 
Reply With Quote
 
 
 
 
Peter van der Goes
Guest
Posts: n/a
 
      11th Jun 2005

"jay B via DotNetMonster.com" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> BOOKINGS has a Primary key: Number. Two Foreign keys: UCI (link to
> CUSTOMERS) & Code (link to HOLIDAYS).
>
> HOLIDAYS has a Primary Key: Code.
>
> The Database has one-to-many Relationships with Referential Integrity and
> checked cascade UPDATE and DELETE (The many relationship for both links
> being on the BOOKINGS table).
>
> I have designed a GUI using vb.NET (Visual Studio) The connection to the
> Database is via Microsoft Jet 4.0 OLE DB Provider and I have got the
> following Datasets to work on both the CUSTOMERS and HOLIDAYS tables:
> SELECT, INSERT, DELETE, UPDATE records. On coming to the BOOKINGS table
> (which appears to be an INNER JOIN) I've got the SELECT and DELETE records
> to work, but I'm having major problems getting the INSERT and UPDATE to
> work. View the coding below:
>

Can you provide the complete text of the error messages generated when you
attempt to insert and update using this code? Thanks.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert into the local access table from the external database Jun Microsoft Access 2 3rd Nov 2006 09:28 PM
problems to insert objects in access database =?Utf-8?B?dG9udGF1cnVz?= Microsoft Access 1 23rd Oct 2005 09:55 PM
Combining multiple SQL Update commands for Access database? jack daniels via .NET 247 Microsoft Dot NET 0 31st Mar 2005 10:43 AM
How do I insert a table from Word into an Access Database? =?Utf-8?B?U29ueWE=?= Microsoft Access 2 11th Jan 2005 04:35 AM
insert blank rows in a table for an access database so that I can. =?Utf-8?B?cGhpbCBS?= Microsoft Access 2 20th Oct 2004 08:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:33 PM.