R
Roy
Hey all, I'm a relative newcomer to asp.net and have 2 simple code
snippets below. Everything works fine, I'm just curious if there is a
more efficient way to do the job as the update takes quite a while.
Here's the proc:
****************************************
CREATE PROCEDURE [Update_Unassigned_VD]
@Recon char(10),
@Book nvarchar(50),
@Van nvarchar(5),
@ContNum nvarchar(8),
@VDN nvarchar(8),
@POE nvarchar(4),
@Shipname nvarchar(50),
@Saildate nvarchar(20),
@POD nvarchar(4),
@Carrier nvarchar(8),
@PCFN nvarchar(10),
@TCN nvarchar(20),
@Lastevent nvarchar(5),
@leloc nvarchar(50),
@leshipname nvarchar(50),
@ccity nvarchar(50),
@preBook nvarchar(50),
@preVan nvarchar(5),
@preCNUM nvarchar(8)
AS
SET NOCOUNT ON
UPDATE [first]
SET carrier_booking_nr = @Book,
van_owner = @Van,
tcon_container_num = @ContNum,
voydoc = @VDN,
poe = @POE,
Ship_Name = @Shipname,
minof315_event_date = @Saildate,
pod = @POD,
ocean_carrier_cd = @Carrier,
PCFN = @PCFN,
tcn = @TCN,
lastevent = @Lastevent,
lasteventloc = @leloc,
Lastevent_shipname = @leshipname,
consigneecity = @ccity,
Recon_Status = @Recon
WHERE carrier_booking_nr = @preBook AND
van_owner = @preVan AND
tcon_container_num = @preCNUM
GO
*****************************
Here's the vb code (this is the "update" portion of a datagrid, btw)
which calls the stored proc:
************************************
Sub FVDGrid_UpdateCommand(Sender As Object, E As
DataGridCommandEventArgs)
FVDConnection = New SqlConnection(blahblahblah)
Dim strRecon as String = CType(e.Item.Cells(2).Controls(0),
TextBox).Text
Dim strBook As String = CType(e.Item.Cells(3).Controls(0),
TextBox).Text
Dim strVan As String = CType(e.Item.Cells(4).Controls(0), TextBox).Text
Dim strContNum as String = CType(e.Item.Cells(5).Controls(0),
TextBox).Text
Dim strVDN as String = CType(e.Item.Cells(6).Controls(0), TextBox).Text
Dim strPoE as String = CType(e.Item.Cells(7).Controls(0), TextBox).Text
Dim strShipName as String = CType(e.Item.Cells(8).Controls(0),
TextBox).Text
Dim strSailDate as String = CType(e.Item.Cells(9).Controls(0),
TextBox).Text
Dim strPod as String = CType(e.Item.Cells(10).Controls(0),
TextBox).Text
Dim strCarrier As String = CType(e.Item.Cells(11).Controls(0),
TextBox).Text
Dim strPCFN as String = CType(e.Item.Cells(12).Controls(0),
TextBox).Text
Dim strTCN as String = CType(e.Item.Cells(13).Controls(0),
TextBox).Text
Dim strLastEvent As String = CType(e.Item.Cells(14).Controls(0),
TextBox).Text
Dim strLELoc as String = CType(e.Item.Cells(15).Controls(0),
TextBox).Text
Dim strLEShipName as String = CType(e.Item.Cells(17).Controls(0),
TextBox).Text
Dim strCCity as String = CType(e.Item.Cells(18).Controls(0),
TextBox).Text
Dim objCommand As SqlCommand = New SqlCommand("Update_Unassigned_VD",
FVDConnection)
Dim Cnt_Command As SqlCommand = New SqlCommand("Update_Counts",
FVDConnection)
With objCommand
..CommandType = CommandType.StoredProcedure
..Parameters.Add (New SqlParameter("@Recon", SqlDbType.char,10)).Value =
strRecon.Trim
..Parameters.Add (New SqlParameter("@Book",
SqlDbType.nvarchar,50)).Value = strBook.Trim
..Parameters.Add (New SqlParameter("@Van", SqlDbType.nvarchar,5)).Value
= strVan.Trim
..Parameters.Add (New SqlParameter("@ContNum",
SqlDbType.nvarchar,8)).Value = strContNum.Trim
..Parameters.Add (New SqlParameter("@VDN", SqlDbType.nvarchar,8)).Value
= strVDN.Trim
..Parameters.Add (New SqlParameter("@POE", SqlDbType.nvarchar,4)).Value
= strPoE.Trim
..Parameters.Add (New SqlParameter("@Shipname",
SqlDbType.nvarchar,50)).Value = strShipName.Trim
..Parameters.Add (New SqlParameter("@Saildate",
SqlDbType.nvarchar,20)).Value = strSailDate.Trim
..Parameters.Add (New SqlParameter("@POD", SqlDbType.nvarchar,4)).Value
= strPod.Trim
..Parameters.Add (New SqlParameter("@Carrier",
SqlDbType.nvarchar,8)).Value = strCarrier.Trim
..Parameters.Add (New SqlParameter("@PCFN",
SqlDbType.nvarchar,10)).Value = strPCFN.Trim
..Parameters.Add (New SqlParameter("@TCN", SqlDbType.nvarchar,20)).Value
= strTCN.Trim
..Parameters.Add (New SqlParameter("@Lastevent",
SqlDbType.nvarchar,5)).Value = strLastEvent.Trim
..Parameters.Add (New SqlParameter("@leloc",
SqlDbType.nvarchar,50)).Value = strLELoc.Trim
..Parameters.Add (New SqlParameter("@leshipname",
SqlDbType.nvarchar,50)).Value = strLEShipName.Trim
..Parameters.Add (New SqlParameter("@ccity",
SqlDbType.nvarchar,50)).Value = strCCity.Trim
..Parameters.Add (New SqlParameter("@preBook",
SqlDbType.nvarchar,50)).Value = strPreBook
..Parameters.Add (New SqlParameter("@preVan",
SqlDbType.nvarchar,5)).Value = strPreVan
..Parameters.Add (New SqlParameter("@preCNUM",
SqlDbType.nvarchar,8)).Value = strPreCNUM
End With
FVDConnection.Open()
objCommand.ExecuteNonQuery()
Cnt_Command.ExecuteNonQuery()
FVDConnection.Close()
FVDGrid.EditItemIndex = -1
FVDGrid.DataBind()
Bind_FVD_Grid()
End Sub
snippets below. Everything works fine, I'm just curious if there is a
more efficient way to do the job as the update takes quite a while.
Here's the proc:
****************************************
CREATE PROCEDURE [Update_Unassigned_VD]
@Recon char(10),
@Book nvarchar(50),
@Van nvarchar(5),
@ContNum nvarchar(8),
@VDN nvarchar(8),
@POE nvarchar(4),
@Shipname nvarchar(50),
@Saildate nvarchar(20),
@POD nvarchar(4),
@Carrier nvarchar(8),
@PCFN nvarchar(10),
@TCN nvarchar(20),
@Lastevent nvarchar(5),
@leloc nvarchar(50),
@leshipname nvarchar(50),
@ccity nvarchar(50),
@preBook nvarchar(50),
@preVan nvarchar(5),
@preCNUM nvarchar(8)
AS
SET NOCOUNT ON
UPDATE [first]
SET carrier_booking_nr = @Book,
van_owner = @Van,
tcon_container_num = @ContNum,
voydoc = @VDN,
poe = @POE,
Ship_Name = @Shipname,
minof315_event_date = @Saildate,
pod = @POD,
ocean_carrier_cd = @Carrier,
PCFN = @PCFN,
tcn = @TCN,
lastevent = @Lastevent,
lasteventloc = @leloc,
Lastevent_shipname = @leshipname,
consigneecity = @ccity,
Recon_Status = @Recon
WHERE carrier_booking_nr = @preBook AND
van_owner = @preVan AND
tcon_container_num = @preCNUM
GO
*****************************
Here's the vb code (this is the "update" portion of a datagrid, btw)
which calls the stored proc:
************************************
Sub FVDGrid_UpdateCommand(Sender As Object, E As
DataGridCommandEventArgs)
FVDConnection = New SqlConnection(blahblahblah)
Dim strRecon as String = CType(e.Item.Cells(2).Controls(0),
TextBox).Text
Dim strBook As String = CType(e.Item.Cells(3).Controls(0),
TextBox).Text
Dim strVan As String = CType(e.Item.Cells(4).Controls(0), TextBox).Text
Dim strContNum as String = CType(e.Item.Cells(5).Controls(0),
TextBox).Text
Dim strVDN as String = CType(e.Item.Cells(6).Controls(0), TextBox).Text
Dim strPoE as String = CType(e.Item.Cells(7).Controls(0), TextBox).Text
Dim strShipName as String = CType(e.Item.Cells(8).Controls(0),
TextBox).Text
Dim strSailDate as String = CType(e.Item.Cells(9).Controls(0),
TextBox).Text
Dim strPod as String = CType(e.Item.Cells(10).Controls(0),
TextBox).Text
Dim strCarrier As String = CType(e.Item.Cells(11).Controls(0),
TextBox).Text
Dim strPCFN as String = CType(e.Item.Cells(12).Controls(0),
TextBox).Text
Dim strTCN as String = CType(e.Item.Cells(13).Controls(0),
TextBox).Text
Dim strLastEvent As String = CType(e.Item.Cells(14).Controls(0),
TextBox).Text
Dim strLELoc as String = CType(e.Item.Cells(15).Controls(0),
TextBox).Text
Dim strLEShipName as String = CType(e.Item.Cells(17).Controls(0),
TextBox).Text
Dim strCCity as String = CType(e.Item.Cells(18).Controls(0),
TextBox).Text
Dim objCommand As SqlCommand = New SqlCommand("Update_Unassigned_VD",
FVDConnection)
Dim Cnt_Command As SqlCommand = New SqlCommand("Update_Counts",
FVDConnection)
With objCommand
..CommandType = CommandType.StoredProcedure
..Parameters.Add (New SqlParameter("@Recon", SqlDbType.char,10)).Value =
strRecon.Trim
..Parameters.Add (New SqlParameter("@Book",
SqlDbType.nvarchar,50)).Value = strBook.Trim
..Parameters.Add (New SqlParameter("@Van", SqlDbType.nvarchar,5)).Value
= strVan.Trim
..Parameters.Add (New SqlParameter("@ContNum",
SqlDbType.nvarchar,8)).Value = strContNum.Trim
..Parameters.Add (New SqlParameter("@VDN", SqlDbType.nvarchar,8)).Value
= strVDN.Trim
..Parameters.Add (New SqlParameter("@POE", SqlDbType.nvarchar,4)).Value
= strPoE.Trim
..Parameters.Add (New SqlParameter("@Shipname",
SqlDbType.nvarchar,50)).Value = strShipName.Trim
..Parameters.Add (New SqlParameter("@Saildate",
SqlDbType.nvarchar,20)).Value = strSailDate.Trim
..Parameters.Add (New SqlParameter("@POD", SqlDbType.nvarchar,4)).Value
= strPod.Trim
..Parameters.Add (New SqlParameter("@Carrier",
SqlDbType.nvarchar,8)).Value = strCarrier.Trim
..Parameters.Add (New SqlParameter("@PCFN",
SqlDbType.nvarchar,10)).Value = strPCFN.Trim
..Parameters.Add (New SqlParameter("@TCN", SqlDbType.nvarchar,20)).Value
= strTCN.Trim
..Parameters.Add (New SqlParameter("@Lastevent",
SqlDbType.nvarchar,5)).Value = strLastEvent.Trim
..Parameters.Add (New SqlParameter("@leloc",
SqlDbType.nvarchar,50)).Value = strLELoc.Trim
..Parameters.Add (New SqlParameter("@leshipname",
SqlDbType.nvarchar,50)).Value = strLEShipName.Trim
..Parameters.Add (New SqlParameter("@ccity",
SqlDbType.nvarchar,50)).Value = strCCity.Trim
..Parameters.Add (New SqlParameter("@preBook",
SqlDbType.nvarchar,50)).Value = strPreBook
..Parameters.Add (New SqlParameter("@preVan",
SqlDbType.nvarchar,5)).Value = strPreVan
..Parameters.Add (New SqlParameter("@preCNUM",
SqlDbType.nvarchar,8)).Value = strPreCNUM
End With
FVDConnection.Open()
objCommand.ExecuteNonQuery()
Cnt_Command.ExecuteNonQuery()
FVDConnection.Close()
FVDGrid.EditItemIndex = -1
FVDGrid.DataBind()
Bind_FVD_Grid()
End Sub