Wednesday, July 22, 2020

How to check if a set of key and value already exists in a dictionary

Dictionary<int, string> dict = new Dictionary<int, string>();
// initial value for demonstration
dict.Add(1, "Test");
dict.Add(2, "Test2");

use below method to check whether a key is exist or not

  if (!dict.ContainsKey(1))
        dict.Add(1, "Test");

 if (!dict.ContainsValue("Test"))
        dict.Add(1, "Test");

Monday, June 29, 2020

Error when pasting text in IE

The code for the event handler that is called when pasting some text into the input control throws an error because 'e.originalEvent.clipboardData' or  "Invalid argument" is undefined in Internet Explorer.


This code applies the fix and works fine

_searchInput.on('paste', function (e) {
var data;
if (window.clipboardData && window.clipboardData.getData) { // IE
data = window.clipboardData.getData('Text');
}
else if (e.originalEvent.clipboardData && e.originalEvent.clipboardData.getData) { // other browsers
data = e.originalEvent.clipboardData.getData('text/plain');
}

Tuesday, February 25, 2020

disable Parameter_Sniffing at the database level

The Parameter_Sniffing option can be disabled using the below ALTER DATABASE statement:

ALTER DATABASE SCOPED CONFIGURATION SET PARAMETER_SNIFFING = OFF;



from the Options tab of the Database Properties window, by changing the Parameter_Sniffing value to OFF as follows:



Monday, February 24, 2020

search text file using c# and display the line number and the complete line that contains the search keyword


Sample Input:

just a sample line
another sample line
first matching Order line
not a match
...here's a Order  match
Order 123

foreach (var match in File.ReadLines(@"c:\LogFile.txt")
                          .Select((text, index) => new { text, lineNumber = index+ 1 })
                          .Where(x => x.text.Contains("Order ")))
{
    Console.WriteLine("{0}: {1}", match.lineNumber, match.text);
}



Output:

3: first matching Order line
5: ...here's a Order  match
6: Order 123

Sunday, February 23, 2020

How can i call a server side button click function from client side?

option is to simulate Click of a button using javascript.
<asp:Button ID="savebtn" runat="server" OnClick="savebtn_Click" style="display:none" />
HTML markup will look like this:

<button id="btnsave" onclick="fncsave()">Save</button>
now simulate a Click using JS

<script type="text/javascript">
     function fncsave()
     {
        document.getElementById('<%= savebtn.ClientID %>').click();
     }
</script>

Friday, February 21, 2020

How use hidden field value in updatepanel

Any asynchronous round trips to the server will cause only those controls within the UpdatePanelitself to update on the UI, so even though the code-behind runs and updates the hidden fields, on the front end they stay the same because they sit outside the panel.

Try moving the hidden fields within the <ContentTemplate> tag

<asp:UpdatePanel ID="upTripsGrid" runat="server" UpdateMode="Always">
  <ContentTemplate>
         <input type="hidden" runat="server" id="hidCurrentDate" value="" />
         <input type="hidden" runat="server" id="hidTripIds" value="" />
  </ContentTemplate>
</asp:UpdatePanel>

Wednesday, February 19, 2020

How do I copy to the clipboard in JavaScript?

html page: 

 <button onclick="copyToClipboard();return false">copy to the clipboard</button> 
 <asp:HiddenField runat="server" ID="hdnCopyContent" ClientIDMode="Static" value="clipboard in JavaScript" />

Javascript function

function copyToClipboard() {     
        var text = $("input[Id$='hdnCopyContent']").val();
        if (text != undefined || text != null || text != "") {       
            alert(text);
        }       
        if (window.clipboardData && window.clipboardData.setData) {
            // IE specific code path to prevent textarea being shown while dialog is visible.
            return clipboardData.setData("Text", text);

        } else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
            var textarea = document.createElement("textarea");
            textarea.textContent = text;
            textarea.style.position = "fixed";  // Prevent scrolling to bottom of page in MS Edge.
            document.body.appendChild(textarea);
            textarea.select();
            try {
                return document.execCommand("copy");  // Security exception may be thrown by some browsers.
            } catch (ex) {
                console.warn("Copy to clipboard failed.", ex);
                return false;
            } finally {
                document.body.removeChild(textarea);
            }
        }
    }

Why does xcopy exit with code 9009 in Visual Studio post-build step?

xcopy "$(ProjectDir)config\Web.config.$(ConfigurationName)" "$(ProjectDir)Web.config" /Y/R

"'xcopy' is not recognized as an internal or external command."

I then changed my statement to:

C:\Windows\System32\xcopy "$(ProjectDir)config\Web.config.$(ConfigurationName)" "$(ProjectDir)Web.config" /Y/R

Tuesday, February 18, 2020

Getting Columns Headers without Result Data in SQL Server

 SET FMTONLY ON


SET FMTONLY ON returns only metadata to the client. It can be used to test the format of the response without actually running the query. When this setting is ON the resultset only have headers of the results but no data. If resultset has Spatial Results, it will have the spatial results tab as well, however, no spatial data.

sample :-


Monday, February 17, 2020

SQL Server Profiler

What is an SQL Server Profiler?
An SQL server profiler is a tool for tracing, recreating, and troubleshooting problems in MS SQL Server, Microsoft’s Relational Database Management System (RDBMS). The profiler lets developers and Database Administrators (DBAs) create and handle traces and replay and analyze trace results

How it works
It works by giving DBAs and developers a high-level view of the operation of a system. Users create traces to capture data and monitor errors and other problems. They then use the profiler to store, retrieve, and view the results of many traces graphically for purposes of troubleshooting and repair. This function all happens on the client-side, meaning it uses resources on the same machine it’s monitoring.

Benefits

  • Clarity. It can reveal how an instance works when it’s interacting with a client.
  • Troubleshoot problems. It can help zero in on trouble spots by allowing us to capture and replay key events. This function also helps with stress testing and identifying slowly executing queries.
  • Allow non-administrator users to create traces securely. It can cater to the needs of DBAs, developers, database designers, business intelligence specialists, IT professionals, and even accountants.
  • Compare activity to baselines. It lets users save trace data and compare it to newer data to spotlight new trouble spots.
  • Capture traces for Transact-SQL, SSIS, and Analysis Services.

Thursday, February 6, 2020

SQL join: where clause vs. on clause


SELECT *
FROM Orders
LEFT JOIN OrderLines ON OrderLines.OrderID=Orders.ID
WHERE Orders.ID = 12345
and

SELECT *
FROM Orders
LEFT JOIN OrderLines ON OrderLines.OrderID=Orders.ID
    AND Orders.ID = 12345


a. WHERE clause: After joining. Records will be filtered after join has taken place.

b. ON clause - Before joining. Records (from right table) will be filtered before joining

JavaScript — What’s the difference between Null & Undefined?

null is an assigned value. It means nothing.
undefined means a variable has been declared but not defined yet.
null is an object. undefined is of type undefined.
null !== undefined but null == undefined.

Differences between Response.End() and Response.Flush()

Response.Flush
Forces all currently buffered output to be sent to the client. The Flush method can be called multiple times during request processing.
Response.End
Sends all currently buffered output to the client, stops execution of the page, and raises the EndRequest event.

You should try using this code if you are not doing any processing on the page after Response.Write and want to stop processing the page.
    context.HttpContext.Response.Clear();
    context.HttpContext.Response.Write(htmlString);              
    context.HttpContext.Response.Flush(); // send all buffered output to client 
    context.HttpContext.Response.End(); // response.end would work fine now.

Change default Port on Next.js app

 If any other app or process is running on port 3000 , you will get this error in your terminal Port 3000 is already in use. error Command f...