Friday, September 22, 2017

How to Create Temp Table From Stored Procedure?



Some questions never get old. This is one such question, which I keep on hearing for many years and I hear it often. I often get asked this question in my 
There are cases when we do NOT know the resultset of the stored procedure and we want to populate the table based of it. We can execute following code.
1
2
3
4
5
SELECT * INTO #TestTableT FROM OPENROWSET('SQLNCLI', 'Server=localhost;Trusted_Connection=yes;',
'EXEC tempdb.dbo.GetDBNames')
-- Select Table
SELECT *
FROM #TestTableT;
The disadvantage of this code is that it bit complicated, but it usually works well in the case of the column names are not known.
Just note that if you are getting error in this method enable ad hoc distributed queries by executing following query in SSMS.
1
2
3
4
5
6
7
8
sp_configure 'Show Advanced Options', 1
GO
RECONFIGURE
GO
sp_configure 'Ad Hoc Distributed Queries', 1
GO
RECONFIGURE
GO
Let me know if you have ever faced such situation in your business. If yes, please leave a comment as I would love to read your experience.
Just so you know not only temporary table, but you can also create a regular table using the method explained in this blog post.

Friday, March 13, 2015

Principles for keeping your code clean

 The art of writing HTML and CSS is the foundation of a beautiful website. The advantages of clean, semantic HTML are many, but so many websites suffer from poorly written markup.

Most of the attractive website have beautiful designs but fails to pass in the w3c validations. This is because of bad coding. These are the basic and most follow principles for keeping your code clean and have a semantic structure. They are as follows...

1. Strict DOCTYPE
2. Proper indentation
3. Nest your tags properly
4. Character set & encoding characters
5. Eliminate unnecessary divs
6. Use better naming conventions
7. Leave typography to the CSS
8. Use Class/id the body tag
9. Keep your CSS and JavaScript external
10. Validation

This will be a great start to write clean HTML, but there is still lots more. When starting from scratch, this seems to be much easier. When trying to fix existing code, it feels a lot more difficult. SO from the next project, just think what you can make it right.

Google: native C in Hadoop with MapReduce for C

 Google's open source elves have released MapReduce for C (MR4C), an open source framework to run native C-language code in Hadoop.
What?
MR4C.png
MR4C is an open source software "framework" designed to allow software programmers to run their native C and C++ code on Hadoop for its big data analytics capabilities.
MR4C is an implementation framework that allows programmers to run native code within the Hadoop execution framework.
Pairing the performance and flexibility of natively developed algorithms with the "unfettered scalability and throughput" inherent in Hadoop, MR4C enables large-scale deployment of advanced data processing applications.
MapReduce itself can be described as a "programming model" with a parallel distributed algorithm for creating software code that is capable of processing and performing calculations upon (and then ultimately also generating) what are very large data sets.
Why?
Being able to run native code means developers can avoid having to construct additional libraries -- and Hadoop is of course written in Java.
Still ... why?
What kind of code would be so big that this type of set of algorithms and libraries would need to be developed?
Examples include:
• High performance scientific computing
• Satellite image processing
• Industrial data clusters serving Internet of Things
• Geospatial data science
... and finally, why?
What Google wants to do is be able to abstract the details of MapReduce (as a programming model and framework) and so therefore allow developers to create more pure-bred algorithms, which (in theory) will always perform with more power, flexibility and speed.
Google explains that it was attracted by the job tracking and cluster management capabilities of Hadoop for scalable data handling, but wanted to leverage the image processing libraries that have been developed in C and C++.
"While many software companies that deal with large datasets have built proprietary systems to execute native code in MapReduce frameworks, MR4C represents a flexible solution in this space for use and development by the open source community," said Google, on its open source blog.
Blogger Ty Kennedy-Bowdoin continues, "MR4C is developed around a few simple concepts that facilitate moving your native code to Hadoop. Algorithms are stored in native shared objects that access data from the local filesystem or any uniform resource identifier (URI), while input/output datasets, runtime parameters, and any external libraries are configured using JavaScript Object Notation (JSON) files."

Sunday, March 10, 2013

Add,Delete Client side GridviewRow and save Record in server side in asp.net

function AddNewRecord() {
         
         var grd = document.getElementById('GridView1');
         var tbod = grd.rows[0].parentNode;
         var newRow = grd.rows[grd.rows.length - 1].cloneNode(true);        
         tbod.appendChild(newRow);
         return false;

     }
 function delrow(rowindex) {
        
         
                var grd = document.getElementById('GridView1');
                if (grd.rows.length < 2)
                    alert("At least 1 Item is required.");
                else
                 var tbod = grd.rows[0].parentNode;

                  tbod.deleteRow(rowindex.parentNode.parentNode.rowIndex);
                   
                  // grd.deleteRow(rowindex + 1);
                  return false;

     }
  <asp:Button ID="Button2" runat="server" Text="Add Row" OnClientClick="return AddNewRecord();"/>
  
  <asp:GridView ID="GridView1" runat="server"
        AlternatingItemStyle-CssClass="row_white" AutoGenerateColumns="False"
        CssClass="row_blue" Width="50%">
        <HeaderStyle CssClass="header" />
        <Columns>
      


        
         <asp:TemplateField>
                <ItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
           
          <asp:TemplateField HeaderText="delete">
                <ItemTemplate>
           
        
                                                                <img src="../images/delete.png" alt="Delete" style="cursor: pointer; padding-right: 20px"
                                                                onclick="delrow(this);" title="Delete" width="10" height="11" />
                                                              
            
               </ItemTemplate>
            </asp:TemplateField>
           
           
           
                                         
        </Columns>
    </asp:GridView>
   
and save Record in Server side Database

int liCounter = 1;
        while (!string.IsNullOrEmpty(Request.Form["GridView1$ctl" + liCounter.ToString()+"$TextBox"+ liCounter.ToString()]))
        {        
            string str = Convert.ToString(Request.Form["GridView1$ctl" + liCounter.ToString() + "$TextBox" + liCounter.ToString()]); //percentage         
            liCounter++;

            Response.Write(str+"<br>");
        }



Dynamic Tooltips Asp.net




style type="text/css">

#dhtmltooltip{
position: absolute;
width: 150px;
border: 1px solid skyblue;
padding: 2px;
background-color: #cad4e7;
visibility: hidden;
z-index: 100;
/*Remove below line to remove shadow. Below line should always appear last within this CSS*/
filter: progid:DXImageTransform.Microsoft.Shadow(color=#cad4e7,direction=135);
}

</style>






    <asp:TemplateField HeaderText="ID">
 
                                        <ItemTemplate>
                                           
                                    <div onmouseover="shownow('Status:<%# Eval("Status_Name") %>,Visit Date:<%# Eval("Visit_Date") %>,mangesh,raj,vis')"
                                     onmouseout="hideddrivetip();">       
                                 <asp:LinkButton id="lnkID" CssClass="TableDataLink" runat="server" Text='<%# Bind("Status_Name") %>'
                                  ToolTip='<%# Bind("Status_Name") %>' ></div>
                                    </asp:LinkButton>

                                    </div>
                                       
                                        </ItemTemplate>
                                    </asp:TemplateField>     












<div id="dhtmltooltip"></div>
            <script type="text/javascript">
            

                var offsetxpoint = -60 //Customize x offset of tooltip
                var offsetypoint = 20 //Customize y offset of tooltip
                var ie = document.all
                var ns6 = document.getElementById && !document.all
                var enabletip = false
                if (ie || ns6)
                    var tipobj = document.all ? document.all["dhtmltooltip"] : document.getElementById ? document.getElementById("dhtmltooltip") : ""

                function ietruebody() {
                    return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
                }

                function ddrivetip(thetext, thecolor, thewidth) {
                    if (ns6 || ie) {
                        if (typeof thewidth != "undefined") tipobj.style.width = thewidth + "px"
                        if (typeof thecolor != "undefined" && thecolor != "") tipobj.style.backgroundColor = thecolor
                        tipobj.innerHTML = thetext
                        enabletip = true
                        return false
                    }
                }

                function positiontip(e) {
                    if (enabletip) {
                        var curX = (ns6) ? e.pageX : event.clientX + ietruebody().scrollLeft;
                        var curY = (ns6) ? e.pageY : event.clientY + ietruebody().scrollTop;
                        //Find out how close the mouse is to the corner of the window
                        var rightedge = ie && !window.opera ? ietruebody().clientWidth - event.clientX - offsetxpoint : window.innerWidth - e.clientX - offsetxpoint - 20
                        var bottomedge = ie && !window.opera ? ietruebody().clientHeight - event.clientY - offsetypoint : window.innerHeight - e.clientY - offsetypoint - 20

                        var leftedge = (offsetxpoint < 0) ? offsetxpoint * (-1) : -1000

                        //if the horizontal distance isn't enough to accomodate the width of the context menu
                        if (rightedge < tipobj.offsetWidth)
                        //move the horizontal position of the menu to the left by it's width
                            tipobj.style.left = ie ? ietruebody().scrollLeft + event.clientX - tipobj.offsetWidth + "px" : window.pageXOffset + e.clientX - tipobj.offsetWidth + "px"
                        else if (curX < leftedge)
                            tipobj.style.left = "5px"
                        else
                        //position the horizontal position of the menu where the mouse is positioned
                            tipobj.style.left = curX + offsetxpoint + "px"

                        //same concept with the vertical position
                        if (bottomedge < tipobj.offsetHeight)
                            tipobj.style.top = ie ? ietruebody().scrollTop + event.clientY - tipobj.offsetHeight - offsetypoint + "px" : window.pageYOffset + e.clientY - tipobj.offsetHeight - offsetypoint + "px"
                        else
                            tipobj.style.top = curY + offsetypoint + "px"
                        tipobj.style.visibility = "visible"
                    }
                }

                function hideddrivetip() {
                    if (ns6 || ie) {
                        enabletip = false
                        tipobj.style.visibility = "hidden"
                        tipobj.style.left = "-1000px"
                        tipobj.style.backgroundColor = ''
                        tipobj.style.width = ''
                    }
                }

                document.onmousemove = positiontip


                function shownow(str) {
                    // debugger;<img src= />
                
                  //  sleep(1000);
                  
                   // ddrivetip(tblstart + listr + tblend, '#cad4e7', 250);

                    var myarray = str.split(',');
                    var tblstart = '<table><tr><td ><font color="darkred" size="0.5">';
                    var listr='';

                    var tblend = '</font></td></tr></table>';

                    for (var i = 0; i < myarray.length; i++) {
                        //console.log(myarray[i]);
                        listr =listr+ '<li>' + myarray[i] + '</li>';

                    }

                   // alert(tblstart + listr + tblend);
                   // ddrivetip('<table><tr><td width="100%"><font color="darkred" size="0.5"><li>' + str + '</font></td></tr></table>', '#cad4e7', 250);

                    ddrivetip(tblstart + listr + tblend, '#cad4e7', 0);

                }

                function sleep(ms) {
                    ddrivetip('<img src="../images/loading.gif" />', 'red', 470);
                    var dt = new Date();
                    dt.setTime(dt.getTime() + ms);
                    while (new Date().getTime() < dt.getTime());
                }

            </script>

CSS Form

Tuesday, February 22, 2011

write Log into Text File

Public Shared Function Trace(ByVal Message As String) As String
Dim Str As String
Str = DateTime.Now.Date
Dim FILE_NAME As String = "D:\R" + Str.Replace("/", "-") + ".txt"
Dim sw As StreamWriter
If System.IO.File.Exists(FILE_NAME) = True Then
System.Diagnostics.Process.GetProcessesByName(FILE_NAME)
sw = System.IO.File.AppendText(FILE_NAME)
sw.Write(DateTime.Now + "____________" + Message)
sw.WriteLine()
sw.Close()
Else
sw = File.CreateText(FILE_NAME)
End If
End Function