troubleshooting Question

How should I load a VB array of Class (within VB 2010 Express) to a SQL Server database table ?

Avatar of Beamson
Beamson asked on
Visual Basic.NETMicrosoft SQL Server 2008
5 Comments1 Solution375 ViewsLast Modified:
I am using Visual Basic 2010 Express.
I have an API which returns, amongst other things, an array of a class.
I want to load the information in this array to a SQL server 2008 Express database.

The items in the class are simple datatypes (dates, integers, strings etc) and can be mapped to SQL datatypes.

So, my current solution works, but is a bit ugly.

If the API returns AllPeople, my code goes something like:

With AllPeople
  For i = 0 to .PeopleData.Length - 1
    With .PeopleData(i)
      MySqlCommand = New SqlCommand("SpInsertPeople", ConSql)
      MySqlCommand.Parameters.AddWithValue("Forename", .forename)
      MySqlCommand.Parameters.AddWithValue("Surname", .surname)
    End With
End With 

So, I'm looping through the index of the array and for each item in the array, I'm adding the class values to parameters for a stored procedure and executing it. (The stored procedure adds new records, updates exisiting ones)

Currently, the size of the array is fairly small - say tens or hundreds of records - but it will grow to several thousand.  I don't want to be hammering my SQL server with tens of thousands of seperate executions of stored procedures. This process will have to repeat every 30 seconds or so.

So, is there a cleaner way of getting data from an array of class into a SQL Server table?
Or is For... Execute stored procedure...  Next...    as good as it gets?
Haver RamirezIT Development

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros