Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How to execute multiple queries with one connection in vb.net.
I am using windows vb.net with Access DB.

In my project i need to delete the records of 15 tables.
Every time i need to open the connection and close the connection for every delete statement.
Same way i need to insert the records for 15 to 20 tables.
It took lot of time to execute.

is it possible to delete the records from multiple tables with one connections?

Need code for this

Sucharitha
Posted
Comments
Maciej Los 17-Jul-13 8:21am    
Who do you said that you need to open/close connection every time when you execute query?
Jean A Brandelero 17-Jul-13 8:22am    
Yes, it is possible. Just make this connection public, open it, run all your tasks then close the connection.

Like:

Shared con as SqlConnection;

OpenConnection()
DeleteStuff()
CloseConnection()
Maciej Los 17-Jul-13 8:27am    
It's not SQLConnection. It's OLEDBConnection, because of MS Access database! Please, read question carefuly.
Jean A Brandelero 17-Jul-13 8:28am    
This was just an example, not a solution. The idea is the same.
Maciej Los 17-Jul-13 8:26am    
Improve question and show us your code and example data. Shortly describe why you need to reopen connection...

1 solution

Hey hi

you must be calling sp to achieve this task right
so in once sp also you can delete all your tables..

SQL
USE [LTXFlow]
GO
/****** Object:  StoredProcedure [dbo].[save_Aging]    Script Date: 7/17/2013 5:44:39 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[save_Aging]
@Id int,
@dtTime datetime,
@Status varchar(30),
@UpldMstrId int,
@UpdatedBy int
as
begin
	if @Id=1
	begin


			insert into Tbl1(dtTime,[Status],UpdatedBy,UpldMstrId)values(@dtTime,@Status,@UpdatedBy,@UpldMstrId)
			insert into Tbl2(.....)
insert into Tbl3()
.
.
.
.
	
		
	end
end


instead of calling it 15 times for 15 tables you can add 15 insert statement in one sp.
 
Share this answer
 
Comments
Maciej Los 17-Jul-13 8:23am    
It's not possible to create SP in Access database. It's possible to create a query/queries.
Jean A Brandelero 17-Jul-13 8:26am    
I dont think creating a sp with 12 inserts and a gazilion parameters is a good ideia... And, it will allways be 12 inserts/dels?
sunil mali 17-Jul-13 8:50am    
Uff i just missed that line where it says ACCESS DB...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900