473,406 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Best way to Insert multiple records into a table?

I am wanting to Insert multiple records into a table, and although I have some working code I feel that there must be a better way. The purpose of the code is to do a directory listing of a sub-directory and for each file listed insert a record into a temporary table.

Can anyone help?

My code is as follows....

SQL Stored Procedure
dbo.sp_bmwrInsSpool @username VarChar(8), @spoolName VarChar(12), @spoolDate VarChar(6) AS

DECLARE @uid Int

SET rowcount 1
SELECT @uid=userid.uid
FROM userid
WHERE username = @username
SET rowcount 0

INSERT INTO bmwrTmp (uid, spoolName, spoolDate)
VALUES (@uid, @spoolName, @spoolDate)

RETURN

ASP.NET Code (VB.NET)
Sub GetSpoolFileListing
Dim FilSysObj = Server.CreateObject("Scripting.FileSystemObject")
Dim Folder = FilSysObj.GetFolder("\\huksrv03\bmliv$\bmpc\DATA\B RANCH00\Spool")
Dim FolderContents = Folder.Files
Dim File

For Each File in FolderContents
InsertSpoolFile(File.Name)
Next
End Sub

Sub InsertSpoolFile(sFileName As String)
Dim SqlConn As New SqlConnection(ConfigurationSettings.AppSettings("h ibdb"))
Dim CmdTxt As String = "sp_bmwrInsSpool"
Dim SqlCmd As New SqlCommand(CmdTxt, SqlConn)
Dim rowsAffected As Integer = 0
sqlCmd.CommandType = CommandType.StoredProcedure

SqlCmd.Parameters.Add(New SQLParameter("@username", Context.User.Identity.Name))
SqlCmd.Parameters.Add(New SQLParameter("@spoolName", sFileName))
SqlCmd.Parameters.Add(New SQLParameter("@spoolDate", ""))

SqlConn.Open
Try
rowsaffected=SqlCmd.ExecuteNonQuery
Catch
' lblStatus.Text = "Insert not successful ! Possible dupilcate reference."
Finally
SqlConn.Close
End Try
End Sub

Nov 19 '05 #1
1 2298
It looks good to me. There are ways to insert multiple rows with one stored
procedure call but they are hacks and kludges.
Nov 19 '05 #2

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

Similar topics

10
by: shank | last post by:
I have a recordset that contains multiple records of product a user is purchasing. For clarity, I converted the recordset fields to variables. I need to take that entire recordset and insert it...
8
by: Sans Spam | last post by:
Greetings! I have a table that contains all of the function permissions within a given application. These functions are different sections of a site and each has its own permissions (READ, WRITE,...
2
by: Joe | last post by:
Hey, I'm going to give some background on my situation in case anyone can point out a way around my problem altogether... for the problem itself, please skip to the bottom of the post. thanks....
2
by: george | last post by:
This is like the bug from hell. It is kind of hard to explain, so please bear with me. Background Info: SQL Server 7.0, on an NT box, Active Server pages with Javascript, using ADO objects. ...
0
by: Ian Macey | last post by:
I am wanting to Insert multiple records into a table, and although I have some working code I feel that there must be a better way. The purpose of the code is to do a directory listing of a...
12
by: Peter Proost | last post by:
Hi group, has anyone got any suggestions fot the best way to handle this problem, I've got 3 tables for example table A, B, and C table A looks like name, value table B looks like name, value...
34
by: Jeff | last post by:
For years I have been using VBA extensively for updating data to tables after processing. By this I mean if I had to do some intensive processing that resulted in data in temp tables, I would have...
3
by: Bob Alston | last post by:
I have a routine to copy data to new versions of my app via insert into sql statements. Unfortunately, due to evolution of my app, sometimes the new version has more restrictive editing than an...
0
chumlyumly
by: chumlyumly | last post by:
Hello scripters - OS: Mac OSX Language: PHP w/ MySQL database I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The...
3
by: simple simon | last post by:
How would I insert into multiple related tables using a table valued parameter? Is there any way to do this without using a WHILE loop? I know how to insert from a table valued parameter into one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.