I have a winform app (VB 2005) that allows users to export data to
excel, make updates to the excel file and import the data from that
Excel file and update the database.
My question is: Is it best to do it this way, calling the update
stored procedure for every update? Or should I be loading this data
into a staging table, and if all goes well do the 'Real' Update. Or
put this into a data adapter and update from that? The application
will never update a huge amout of records, maybe 500 at the most. But
I would think this wouldn't scale when I have 5000 Records.
<<Snip>>
Using connection As New SqlConnection(g_sRCT_Conn)
'Get UserID
Dim uid As New SqlCommand("dbo.spoc_Get_UserID",
connection)
uid.CommandType = CommandType.StoredProcedure
'Open conn
connection.Open()
'Return Results
Dim uidResult As New SqlParameter("@UserID",
SqlDbType.Int)
uidResult.Direction = ParameterDirection.Output
uid.Parameters.Add(uidResult)
'Input parms
Dim sUID As String = g_sCurrUserDomain & "\" & g_sCurrUser
uid.Parameters.Add("@PrefID", SqlDbType.VarChar).Value =
sUID
'Exec and get user id
uid.ExecuteNonQuery()
Dim uidID As Integer = CInt(uidResult.Value)
uid.Dispose()
'Get total records to update
.Range("H2").Select()
.Selection.End(Excel.XlDirection.xlDown).Select()
Dim iTotalRecs As Integer = .ActiveCell.Row - 1
.Range("H2").Select()
'Loop thru RecordIDs and get notes
Dim dtUpdate As Date = Now()
Do While .ActiveCell.Text <""
If .ActiveCell.Offset(0, iNOTES_OFFSET).Text <""
Then
'Update records
Dim u As New SqlCommand
("dbo.spoc_ev_ImportUpdate", connection)
u.CommandType = CommandType.StoredProcedure
'Return Value
Dim uResult As New SqlParameter("@Result",
SqlDbType.Int)
uResult.Direction = ParameterDirection.Output
u.Parameters.Add(uResult)
'Input Parms
u.Parameters.Add("@ItemID", SqlDbType.Int).Value =
CInt(.ActiveCell.Text)
u.Parameters.Add("@UserID", SqlDbType.Int).Value =
uidID
u.Parameters.Add("@UpdateDate",
SqlDbType.DateTime).Value = dtUpdate
u.Parameters.Add("@Notes",
SqlDbType.VarChar).Value = .ActiveCell.Offset(0, iNOTES_OFFSET).Text
'Update
u.ExecuteNonQuery()
If Not CInt(uResult.Value) = 0 Then
MessageBox.Show("Error updating RecordID "
& .ActiveCell.Text, _
g_sApp_Name, MessageBoxButtons.OK,
MessageBoxIcon.Error)
iCount = -1
bError = True
Else
iCount += 1
Me.ssStatus.Text = "Updating ... " & iCount _
& " of " & iTotalRecs & " Records"
Application.DoEvents()
End If
End If
.ActiveCell.Offset(1, 0).Select()
Loop
End Using
<<Snip>>