Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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 November 29th, 2006, 05:32 AM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default inserting fields in a related database

hi ...
i have created a relational database and my two tables
1)internet and
2)internet_payment
have code_org,duration_hrs as composite keys....
now i have created a form to insert values to it bt it is nt
working...
my code is listed below....
Dim con As OleDbConnection

        Dim str2 As String
        Dim str3 As String
        Dim com2 As OleDbCommand
        Dim com3 As OleDbCommand
        con = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA Source=C:\Documents and Settings\nitpu.ITPVIS19\My Documents\ProjectPtu.mdb")
  str2 = "insert into internet_payment(code_org,duration_hrs,amount,bank ,dd_no,dd_date) values(@code_org,@duration_hrs,@amount,@bank,@dd_n o,@dd_date)"
        str3 = "insert into internet(code_org,duration_hrs) values(@code_org,@duration_hrs)"
        com2 = New OleDbCommand(str2, con)
        com3 = New OleDbCommand(str3, con)

        com2.Parameters.Add("@code_org", TextBox1.Text)
        com2.Parameters.Add("@duration_hrs", DropDownList2.SelectedItem.Text)
        com2.Parameters.Add("@amount", DropDownList3.SelectedItem.Text)
        com2.Parameters.Add("@bank", TextBox12.Text)
        com2.Parameters.Add("@dd_no", TextBox13.Text)
        com2.Parameters.Add("@dd_date", TextBox14.Text)
        com3.Parameters.Add("@code_org", TextBox1.Text)
        com3.Parameters.Add("@duration_hrs", DropDownList2.SelectedItem.Text)
        con.Open()

        com2.ExecuteNonQuery()
        com3.ExecuteNonQuery()

            con.Close()
bt the program gives the following error...
"You cannot add or change a record because a related record is required in table 'internet'"
as im new to asp.net so i need some help to it
any help would be gr8
thnx in advance


 
Old November 29th, 2006, 11:08 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi , FIrst reverse the order of excecute query,
first com3 then com2

com3.ExecuteNonQuery()
com2.ExecuteNonQuery()

then let us know what it results.




 
Old December 4th, 2006, 01:16 AM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi..
the code that u have told me to reverse the order of statements had worked ...
thnx a lot for the gr8 help...
bye n tc

 
Old December 4th, 2006, 09:02 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

But beware . Put this excecute statements inside the transaction.Otherwise if any error in one statment would leave ur data in the table inconsitent state.






Similar Threads
Thread Thread Starter Forum Replies Last Post
database related query dkvaseeta Pro VB Databases 2 February 22nd, 2007 10:59 AM
DATABASE RELATED QUESTION dkvaseeta Access 3 January 13th, 2007 12:17 PM
Inserting into a database jroxit Classic ASP Basics 1 January 2nd, 2006 06:04 PM
Keep from inserting duplicates based on 2 fields tcarnahan SQL Server 2000 3 October 1st, 2004 07:19 AM
Inserting forms fields into Access tsparker Classic ASP Databases 1 October 9th, 2003 03:24 AM





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