Monday, March 12, 2012

list of strings passed into a parameter

I am trying to pass multiple values as parameters into my update command:

UPDATE tblUserDetails SET DeploymentNameID = 102 WHERE ((EmployeeNumber IN (@.selectedusersparam)));

I develop my parameter (@.selectedusersparam) using the following subroutine:

PrivateSub btnAddUsersToDeployment_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles btnAddUsersToDeployment.Click

Dim iValAsInteger = 0

Dim SelectedCollectionAsString

SelectedCollection =""

If (lsbUsersAvail.Items).Count > 1Then

For iVal = 0To lsbUsersAvail.Items.Count - 1

If lsbUsersAvail.Items(iVal).Selected =TrueThen

SelectedCollection = SelectedCollection &"," & lsbUsersAvail.Items(iVal).Value

EndIf

Next

SelectedCollection = Mid(SelectedCollection, 2, Len(SelectedCollection))

Session.Item("SelectedCollectionSession") = SelectedCollection

SqlDataSource4.Update()

ltlUsersMessage.Text =String.Empty

'UPDATE tblUserDetails SET DeploymentNameID = @.DeploymentNameIDparam WHERE (EmployeeNumber IN (@.selectedusersparam))

'SqlDataSource4.UpdateCommand = "UPDATE tblUserDetails SET DeploymentNameID = @.DeploymentNameIDparam WHERE (EmployeeNumber IN (" + SelectedCollection + ")"

Else

ltlUsersMessage.Text ="Select users before adding to deployment. Hold Control for multiselect"

EndIf

EndSub

For some reason the query does not pass the parameters which are "21077679,22648722,22652940,21080617" into the query

I don't understand why.

hi,

could you debug your application, i want to know what actual query is being passed. you've for loop for some list, while debugging does it go inside this loop or not.

also if i am not wrong you've commented out following line

'SqlDataSource4.UpdateCommand = "UPDATE tblUserDetails SET DeploymentNameID = @.DeploymentNameIDparam WHERE (EmployeeNumber IN (" + SelectedCollection + ")".

seems like it is the cause as i dont see other line for setting updatecommand.

please check & let me know.

regards,

satish

|||

This works but does not use parameters:

ProtectedSub btnRemoveUsersFromDeployment_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles btnRemoveUsersFromDeployment.Click

Dim iVal2AsInteger = 0

Dim SelectedCollection2AsString

SelectedCollection2 =""

If (lstUsersToRemoveFromDeployment.Items).Count > 0Then

For iVal2 = 0To lstUsersToRemoveFromDeployment.Items.Count - 1

If lstUsersToRemoveFromDeployment.Items(iVal2).Selected =TrueThen

SelectedCollection2 = SelectedCollection2 &"," & lstUsersToRemoveFromDeployment.Items(iVal2).Value

EndIf

Next

SelectedCollection2 = Mid(SelectedCollection2, 2, Len(SelectedCollection2))

Session.Item("SelectedCollectionSession") = SelectedCollection2

SqlDataSourceInCurrentDeployment.UpdateCommand ="UPDATE tblUserDetails SET DeploymentNameID = null WHERE ((EmployeeNumber IN (" + SelectedCollection2 +")))"

SqlDataSourceInCurrentDeployment.Update()

Else

MsgBox("Please select user(s) first")

EndIf

EndSub

|||

hi,

i am not clear mate...in earlier post you were passing parameter for DeploymentNameID in update command now you've removed and used null!!!

i m confusedEmbarrassed, what is actual problem.

regards,

satish.

|||

I have used the same concept for two different situations.

In the last post I did I was removing the Deployment name ID created by the first update command.

cheers.

Ben.

No comments:

Post a Comment