473,468 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

One Form Multiple Tables

I have one form, should insert data to multiple tables in same database.
Can u give me an example?
Dec 6 '05 #1
1 1224
Hi Dear LacOniC,

What Controls you have on your form? Is it a webform, winform?

But In anycase, what you can do is , write code like this

Dim myConnection As New SqlConnection(myConnString)
myConnection.Open()

Dim myCommand As SqlCommand = myConnection.CreateCommand()
Dim myTrans As SqlTransaction

' Start a local transaction

myTrans = myConnection.BeginTransaction(IsolationLevel.ReadC ommitted,
"SampleTransaction")

' Must assign both transaction object and connection
' to Command object for a pending local transaction

myCommand.Connection = myConnection
myCommand.Transaction = myTrans

Try
myCommand.CommandText = "Insert into Table1(Field1, Field2,.....)
VALUES ('" & textbox1.text.tostring() & "', '" & textbox2.text.tostring() &
"')"
myCommand.ExecuteNonQuery()

myCommand.CommandText = "Insert into Table2(Field1, Field2,.....)
VALUES ('" & textbox1.text.tostring() & "', '" & textbox2.text.tostring() &
"')"
myCommand.ExecuteNonQuery()

myTrans.Commit()

Console.WriteLine("Both records are written to database.")

Catch e As Exception
Try
myTrans.Rollback("SampleTransaction")
Catch ex As SqlException

If Not myTrans.Connection Is Nothing Then
Console.WriteLine("An exception of type " &
ex.GetType().ToString() & _
" was encountered while attempting to roll back
the transaction.")

End If

End Try

Console.WriteLine("An exception of type " & e.GetType().ToString() & _
"was encountered while inserting the data.")
Console.WriteLine("Neither record was written to database.")

Finally

myConnection.Close()

End Try

End Sub 'RunSqlTransaction

For Anything & Everything, Please Let Me Know,

Bye
Venkat_KL
Dec 6 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: L Major | last post by:
Hi Unfortunately, I am limited to using tables for part of my current project. I have a form that spans across a number of TR and TD in the shape of checkboxes. Doctype is XHTML 1.0...
2
by: IanCraft | last post by:
I am new to Access 2002 and have a questions regarding using a form for data entry. I have 15 items I need to keep track of that are listed individually on a form as follows: Item#1Name ...
2
by: Sean | last post by:
Greetings all, I am attempting to make a form that will filter through several tables that (I believe) have refretial integrity. I am pulling data from several tables into the form and i would...
13
by: ricky.agrawal | last post by:
I'm really not sure how to go about this in Access. What I've created is a table for each location. Those tables are identical in format but different in information. The tables are named after...
4
by: knix | last post by:
I have this access project consisting of multiple tables that are linked together in a relationship. I would like to migrate the consolidated information through appending in a datasheet form or...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.