Friday, May 21, 2021

How to : Check if a column exists in a datareader in C#

 Here is how we can do in  C# supported Frameworks!!

var fieldvalues = Enumerable.Range(0, reader.FieldCount).Select(i => reader.GetName(i)).ToArray();

//get column name here
if (fieldvalues.Contains("ErrorMessage"))
{
    errorMessge += Environment.NewLine + " ErrorMessage : " + reader["ErrorMessage"].ToString();
}
//get column name here
if (fieldvalues.Contains("ErrorProcedure"))
{
    errorMessge += Environment.NewLine + " ErrorProcedure : " + reader["ErrorProcedure"].ToString();
}

BTW, ErrorMessage will return the value after checking these fields 

Hope this helps 😀

How to Enable or Disable Fast User Switching in Windows PC

Fast User Switching is an easy way for another person to log on to the computer without logging you off or closing your programs and files. Follow the steps below to for Fast Switch User.

1. To begin, make sure that you have logged in as Administrator or have required administrative rights to change local group policies.

2. Press the Windows +R button.

3. Run dialog box will pop-up,type gpedit.msc. This will open Local Group Policy Editor. (see pic 1 for reference)

4. Now, go to the following location and look for Local Computer Policy in the left pane.

5. Click on Local Computer Policy/Computer Configuration/Administrative Templates/System/Logon. (See Pic 2 for refrence)

6. Just double-click Hide Entry Points for Fast User Switching to bring up a dialog box to change Fast User Switching policy setting.

7. At the top, there are Not Configured, Enabled and Disabled options available. Selecting each setting will let you read its affect in Help section. To disable Hide Entry Points for Fast User Switching, just select Enabled from the list and click OK.

If you need to diable this option, you need to select Disabled from the list. Rest all process is same.

8. Once done, you will have to enforce this change made to Fast User Switching policy setting. To do so, close the Local Group Policy Editor and open the Run dialog box (Windows +R button). Enter the command “gpupdate /force“ and click OK. The policy will be updated and applied on all user accounts.

9. To re-enable Fast User Switching, just choose Not Configured in its policy setting dialog and apply the changes via gpupdate /force command.

Hope this helps setting up mutiple users to login on your PC.

Monday, April 19, 2021

How to get only numbers from string sql

I have column where I need to get only numbers form the string.

Here is how we can do,

SUBSTRING(columnName, PATINDEX('%[0-9]%', columnName), LEN(columnName))

Here's the example with PATINDEX

use databasego
-- inventory Group, Employee , cost center
select [Cost Center], [Inventory Group], Employee, 
SUBSTRING(Employee, PATINDEX('%[0-9]%', Employee), LEN(Employee)) AS EmployeeID
from  tmp_BulkOrder_SP_4_16_21

Hope this helps 😀

Sunday, March 21, 2021

How to remove special characters from a string using a function with RegEx

Here is how you can get remove special characters from a string in SQL

-- SELECT dbo.[RemoveCharSpecialSymbolValue] ('naga3fg@#sai') 
CREATE FUNCTION [dbo].[RemoveCharSpecialSymbolValue](@str VARCHAR(500))  
RETURNS VARCHAR(500)  
BEGIN  
DECLARE @startingIndex int  
SET @startingIndex=0  
WHILE 1=1  
	BEGIN  
	SET @startingIndex= patindex('%[^0-9a-zA-Z]%',@str)  
	IF @startingIndex <> 0  
		BEGIN  
			SET @str = replace(@str,substring(@str,@startingIndex,1),'')  
		END  
	ELSE BREAK;  
END  
RETURN @str  
END   

Hope this helps 😀

Saturday, March 20, 2021

How to remove alpha numeric characters from a string using function with RegEx

Here is how you can get alpha numeric characters from a string in SQL

-- SELECT dbo.[RemoveCharSpecialSymbolIntValue] ('naga3@#sai') 
CREATE FUNCTION [dbo].[RemoveCharSpecialSymbolIntValue](@str VARCHAR(500))  
RETURNS VARCHAR(500)  
BEGIN  
DECLARE @startingIndex int  
SET @startingIndex=0  
	WHILE 1=1  
	BEGIN  
		SET @startingIndex= patindex('%[^0-9.]%',@str)  
		IF @startingIndex <> 0  
		BEGIN  
			SET @str = replace(@str,substring(@str,@startingIndex,1),'')  
		END  
		ELSE BREAK;  
	END  
	RETURN @str  
END 

Hope this helps 😀