delete a composite key record from database
hi..
im new to asp.net n databases...
i have got two tables in my database. these are:-
1)training_details
2)pendingtraining_details
now i want to insert a record in training_details and delete that same record wd less fiels from pendingtraining_details...
i have 8 fields in training_details and 4 in pendingtraining_details.
the fields in pendingtraining_details are:-
1)name_org
2)training_type
3)course
4)request_date
all these fiels are composite keys of this table and same fields are composite keys of trainig_details...
the code that i have tried for performing this operation is...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As OleDbConnection
Dim str1 As String
Dim str2 As String
Dim com1 As OleDbCommand
Dim com2 As OleDbCommand
con = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA Source=C:\Documents and Settings\nitpu.ITPVIS19\My Documents\training_project.mdb")
str1 = "insert into training_details(name_org,training_type,course,req uest_date,start_date,end_date,trainees,incharge_na me) values(@name_org,@training_type,@course,@request_d ate,@start_date,@end_date,@trainees,@incharge_name )"
str2 = "delete from pendingtraining_details where name_org=@name_org & training_type=@training_type & course=@course & request_date=@request_date"
com1 = New OleDbCommand(str1, con)
com2 = New OleDbCommand(str2, con)
com1.Parameters.Add("@name_org", TextBox1.Text)
com1.Parameters.Add("@training_type", TextBox2.Text)
com1.Parameters.Add("@course", TextBox3.Text)
com1.Parameters.Add("@request_date", TextBox8.Text)
com1.Parameters.Add("@start_date", TextBox4.Text)
com1.Parameters.Add("@end_date", TextBox5.Text)
com1.Parameters.Add("@trainees", TextBox6.Text)
com1.Parameters.Add("@incharge_name", TextBox7.Text)
com2.Parameters.Add("@name_org", TextBox1.Text)
com2.Parameters.Add("@training_type", TextBox2.Text)
com2.Parameters.Add("@course", TextBox3.Text)
com2.Parameters.Add("@request_date", TextBox8.Text)
con.Open()
com1.ExecuteNonQuery()
com2.ExecuteNonQuery()
con.Close()
End Sub
but this code is inserting the record but bt nt deleting those from the pendingtraining_details...
i have also swapped my executenonquery() statements but still the same result...
not getting a head out of this trap..
any help wld be gr8...
thanx
|