Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
how can i concat multiple values in single label control?
Posted

If you concatenate string values in C#, you can use + The same applies to SQL Server if you concatenate varchar values in an SQL statement

Addition, example of concatenating in SQL

If you want to concatenate twu strings in the SQL statement, lets say col1 and col2 (both varchar) then your statement could look something like:
SQL
SELECT Col1 + Col2, ... other columns ...
FROM TIMETABLE
WHERE DEPARTMENT_CODE = @depcodeparameter
AND TIME = @sometimeparameter
AND  SEMESTER = @semesterparame
 
Share this answer
 
v2
Comments
Monjurul Habib 17-May-12 14:05pm    
nice advice :), 5+
Wendelius 17-May-12 14:10pm    
Thank you Monjurul :)
Jignesh J patel 17-May-12 14:21pm    
though this solution is correct but i have a problem that i have fire this query for select values SELECT * FROM TIMETABLE WHERE DEPARTMENT_CODE ='" + lbldepartment.SelectedValue + "' AND TIME = '" + "05:00-06:00" + "' AND SEMESTER = '" + lblsemester.SelectedItem + "' " and i want to select multiple values and display on label .... please replay...
Wendelius 17-May-12 14:26pm    
Ok, so you're talking about querying and conditions. For this you should always use parameters. Don't concatenate literal text to an SQL statement. For additional information, see http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparameter.aspx[^]

So your statement should look something like the following:

SELECT * FROM TIMETABLE
WHERE DEPARTMENT_CODE = @depcodeparameter
AND TIME = @sometimeparameter
AND SEMESTER = @semesterparame
Jignesh J patel 17-May-12 14:43pm    
in that case how can i concate values in single label..
Mika already provided you the solution. You can also try another solution if you are looking for concatenates two specified instances of String.

Try String.Concat Method (String, String)

For better detail please navigate the following link:
How to: Concatenate Multiple Strings (C# Programming Guide)

Please let us know if you have further requirement.
 
Share this answer
 
v2
Comments
Wendelius 17-May-12 14:10pm    
Yes, that would also be feasible!
Monjurul Habib 17-May-12 14:13pm    
thank you :)
Jignesh J patel 17-May-12 14:26pm    
though this solution is correct but i have a problem that i have fire this query for select values SELECT * FROM TIMETABLE WHERE DEPARTMENT_CODE ='" + lbldepartment.SelectedValue + "' AND TIME = '" + "05:00-06:00" + "' AND SEMESTER = '" + lblsemester.SelectedItem + "' " and i want to select multiple values and display on label .... please replay...
Monjurul Habib 17-May-12 14:49pm    
what did you try? share you detail code. we need your code sample to guide you properly. I guess you are getting a list using the SELECT query. If i am correct then let me know.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900