locked
Cannot build string from SelectionList control RRS feed

  • Question

  • User-566723589 posted
    Below are two code snippets from an otherwise functioning Pocket PC app. The SelectionList is a checkbox type that allows multiple selections. I am trying to concatenate the selected values into a string, and pass that to a stored procedure that then parses the string and performs a table insert for each selection. So if the user selected four comments from the list, the strComment below might look like: "1,4,5,9", and the sproc would then use this (with the other parameters) to execute 4 inserts. If I hardcode a string in the function below, the sproc will run. If I try to build it using the for each loop I get an error from the db saying it cannot insert NULL, which means in this case the selections are not being passed. Can anybody help please? TIA D. Lewis <mobile:Form onactivate="frmComment_OnActivate" id="frmComment" runat="server"> <mobile:Label id="lblComment" runat="server" Text="Comments" StyleReference="title"></mobile:Label> ID: <mobile:Label id="CommFermID" runat="server"></mobile:Label> Code: <mobile:Label id="CommFermenter" runat="server" Font-Bold="True"></mobile:Label> <Mobile:SelectionList id="lstComment" runat="server" SelectType="CheckBox"> <Item value="0" text="Leaky Zwickle"></Item> <Item value="1" text="Leaky Bung"></Item> <Item value="2" text="Glycol Prob."></Item> <Item value="3" text="Solenoid Prob."></Item> <Item value="4" text="Leaky Tank Top"></Item> <Item value="5" text="Poor Seat Lift"></Item> <Item value="6" text="Leaky Sightglass"></Item> <Item value="7" text="Leaky T-O Valve"></Item> <Item value="8" text="Cold Cone"></Item> <Item value="9" text="Early Crash Chill"></Item> <Item value="10" text="Recipe Change"></Item> <Item value="11" text="Other"></Item> </Mobile:SelectionList> <Mobile:RequiredFieldValidator id="valCommReq" runat="server" Font-Bold="True" ErrorMessage="Please make a selection." ControlToValidate="lstComment" Font-Italic="True"></Mobile:RequiredFieldValidator> <mobile:Command id="cmdComment" onclick="InputComment" runat="server" Text="Input"></mobile:Command> <mobile:Link id="lnkCommBack" runat="server" Font-Size="Small" Text="Cancel" NavigateURL="#frmTanks"></mobile:Link> </mobile:Form> Sub InputComment(Sender As Object, E As EventArgs) if Page.IsValid =true Dim item As MobileListItem Dim strComment as string = "" Dim strSeparator as string = "," Dim oSQLConn As New SqlConnection() Dim oSQLComm As SqlCommand Dim strConnection as string strConnection = "server=Lab;database=SNB01;uid=sa;password=dl4589503;" oSQLConn=New SQLConnection(strConnection) oSQLConn.Open() For Each item in lstComment.Items If (item.Selected) If (strComment.Length>0) strComment=strComment & strSeparator End if strComment=strComment & item.text End if Next oSQLComm=oSQLConn.CreateCommand() With oSQLComm .CommandText="dbo.spMobileInsertComment" .CommandType=CommandType.StoredProcedure .Parameters.Add("@FermID", SqlDbType.Int) .Parameters(0).Value = CommFermID.text .Parameters.Add("@Comment", SqlDbType.Varchar) .Parameters(1).Value = strComment .Parameters.Add("@CellarIni", SqlDbType.Varchar) .Parameters(2).Value = Session("Cellarman") End With oSQLComm.ExecuteNonQuery() oSQLConn.Close ActiveForm = frmTanks End If End Sub
    Tuesday, August 10, 2004 11:53 AM

All replies

  • User-566723589 posted
    The offending line was: strComment=strComment & item.text which should be strComment=strComment & item.VALUE D. Lewis
    Wednesday, August 11, 2004 4:43 PM