1
Answer

Problem with VB to C# code

Photo of el walter

el walter

14y
1.7k
1

First of all sorry my bad english xP...

I'm been traspasing some VB code to C# and i get this problem:

i have a textbox (txtGenerarTxt) and i need to get a code (like 98000010) with a newline

txtGenerarTxt.Text = txtGenerarTxt.Text + (Convert.ToChar(LCR)) + Environment.NewLine ;

in VB, has a vbCrLf to make a \r\n (i suppose) but i get this :

"9800001\r\n"  and i need a new line (that i get with vbCrLf) i been trying with; Environment, "\r\n", char(13)... etc

the multiline option is true

Thanks =)

I hope you understand my bad English xD

 

This is what i get from VB app

txtVB.JPG

 

and this is what i get from C#

txtCsharp.JPG


i found the problem, and it was in other part of the code... sorry and thanks for the reply

Answers (1)

0
Photo of Siva Tiyyagura
NA 26 4 8y

Assuming yout Table1 will have all working day timings(except for leaves) and Table2 will have Leaves information Below TSQL can give you the required result.
SELECT * INTO #Temp
FROM
(
SELECT
[empid]
,[attdate] AS [Date]
,CAST(DAY([attdate]) AS VARCHAR(2))+ '(' +CAST([attdate] AS VARCHAR(25))+')' AS [Day]
,'Status' = CASE WHEN [ workedhours] > 8 THEN 'P' ELSE 'AB' END
FROM [Table1]
UNION
SELECT
[empid]
,[leavedate] AS [Date]
,CAST(DAY([leavedate]) AS VARCHAR(2))+ '(' +CAST([leavedate] AS VARCHAR(25))+')' AS [Day]
,'Status' = 'L'
FROM [Table2]
) AS [Result]

SELECT DISTINCT [Date],[Day] INTO #Temp2 FROM #Temp ORDER BY [Date]

DECLARE @ColumnNames NVarchar(MAX)
DECLARE @SqlQuery NVARCHAR(max)

SELECT @ColumnNames=STUFF((
select ',['+ [Day] +']'
from #Temp2
FOR XML PATH('')
)
,1,1,'')

SET @SqlQuery = N'SELECT [empID],' + @ColumnNames +' FROM (Select [EmpId],[Day],[Status] From #Temp) P Pivot (MAX([Status]) For [Day] in (' +@ColumnNames+'))AS PivotTable;'

EXEC Sp_executeSql @SqlQuery