concatenate two fields in a dropdown list

ArrossyAeromy

New Member
I have a stored procedure which brings back a simple set of data in four columns<BR><BR>ID, Name, Department, whatever<BR><BR>How do I concatenate Name and dept and put a minus sign between before binding to a drop down list<BR><BR>In classic asp you'd just do (psuedo code)<BR><BR>while not rs.eof<BR>response.write(rs("name") & " - " & rs("dept")<BR>rs.movenext<BR>loop<BR><BR>what do you do in .Net?<BR><BR>How do you manipulate the dataset before binding?<BR>I believe that it is best that this is done within your SQL statement, e.g. select (col1 + '-' + col2) as xxx from tablethe sproc is used elsewhere to pull data that will not be used in this form<BR><BR>It is a formatting change that needs to be done and so the code to do it should not be in the stored proc.<BR><BR>I keep hitting this problem of wanting to manipulate datasets before binding but can't find any articles on itYou could add another column to the dataset after you bring it back that concatenates the two columns...for instance:<BR><BR>Dim dc As New DataColumn("NameAndDept", Type.GetType("System.String"), "name + '-' + dept")<BR>yourdataset.Tables("yourtable").Columns.Add(dc)<BR><BR>then bind your listbox to that.<BR><BR>Tim
 
Back
Top