How To Get SQL Instance Using C#

hello guys this a simple tutorial that will give you the list of SQL servers available on your lan . ok lets begin making this just open c# and make a new project and name it whatever and after form finished loading add a button and change the text  to refresh and add combobox and at last add a label to make the ui beautiful now  add a class and name it getsql.cs
how to get sql instance using c# - adding class getsql

ok now you will see the class in the side bar ok now go to getsql.cs and add this codes

using System;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

//Author : Mohamed Shimran
//Blog : http://www.ultimateprogrammingtutorials.blogspot.com

namespace DBGrep
{
 public class SqlLocator
 {
  [DllImport("odbc32.dll")]
  private static extern short SQLAllocHandle(short hType, IntPtr inputHandle, out IntPtr outputHandle);
  [DllImport("odbc32.dll")]
  private static extern short SQLSetEnvAttr(IntPtr henv, int attribute, IntPtr valuePtr, int strLength);
  [DllImport("odbc32.dll")]
  private static extern short SQLFreeHandle(short hType, IntPtr handle); 
  [DllImport("odbc32.dll",CharSet=CharSet.Ansi)]
  private static extern short SQLBrowseConnect(IntPtr hconn, StringBuilder inString, 
   short inStringLength, StringBuilder outString, short outStringLength,
   out short outLengthNeeded);

  private const short SQL_HANDLE_ENV = 1;
  private const short SQL_HANDLE_DBC = 2;
  private const int SQL_ATTR_ODBC_VERSION = 200;
  private const int SQL_OV_ODBC3 = 3;
  private const short SQL_SUCCESS = 0;
  
  private const short SQL_NEED_DATA = 99;
  private const short DEFAULT_RESULT_SIZE = 1024;
  private const string SQL_DRIVER_STR = "DRIVER=SQL SERVER";
 
  private SqlLocator(){}

  public static string[] GetServers()
  {
   string[] retval = null;
   string txt = string.Empty;
   IntPtr henv = IntPtr.Zero;
   IntPtr hconn = IntPtr.Zero;
   StringBuilder inString = new StringBuilder(SQL_DRIVER_STR);
   StringBuilder outString = new StringBuilder(DEFAULT_RESULT_SIZE);
   short inStringLength = (short) inString.Length;
   short lenNeeded = 0;

   try
   {
    if (SQL_SUCCESS == SQLAllocHandle(SQL_HANDLE_ENV, henv, out henv))
    {
     if (SQL_SUCCESS == SQLSetEnvAttr(henv,SQL_ATTR_ODBC_VERSION,(IntPtr)SQL_OV_ODBC3,0))
     {
      if (SQL_SUCCESS == SQLAllocHandle(SQL_HANDLE_DBC, henv, out hconn))
      {
       if (SQL_NEED_DATA ==  SQLBrowseConnect(hconn, inString, inStringLength, outString, 
        DEFAULT_RESULT_SIZE, out lenNeeded))
       {
        if (DEFAULT_RESULT_SIZE < lenNeeded)
        {
         outString.Capacity = lenNeeded;
         if (SQL_NEED_DATA != SQLBrowseConnect(hconn, inString, inStringLength, outString, 
          lenNeeded,out lenNeeded))
         {
          throw new ApplicationException("Unabled to aquire SQL Servers from ODBC driver.");
         } 
        }
        txt = outString.ToString();
        int start = txt.IndexOf("{") + 1;
        int len = txt.IndexOf("}") - start;
        if ((start > 0) && (len > 0))
        {
         txt = txt.Substring(start,len);
        }
        else
        {
         txt = string.Empty;
        }
       }      
      }
     }
    }
   }
   catch (Exception ex)
   {
    //Throw away any error if we are not in debug mode
#if (DEBUG)
    MessageBox.Show(ex.Message,"Acquire SQL Servier List Error");
#endif 
    txt = string.Empty;
   }
   finally
   {
    if (hconn != IntPtr.Zero)
    {
     SQLFreeHandle(SQL_HANDLE_DBC,hconn);
    }
    if (henv != IntPtr.Zero)
    {
     SQLFreeHandle(SQL_HANDLE_ENV,hconn);
    }
   }
 
   if (txt.Length > 0)
   {
    retval = txt.Split(",".ToCharArray());
   }

   return retval;
  }
 }
}

The Switch Case Statement In Visual C# .Net

The switch case statement is also used for making decision, unlike the if else statement , we can not test conditions like "greater than" or "less than" . in switch case we can test the value of a variable and decide what to do if a particular value is stored in the variable.

the syntax for switch statement below


switch(varable to test)

{

case value 1 :
statements if value 1 stored in the variable;
break;

case value 2 :
statements if value 2 stored in the variable;
break;

*
*
default:
statements if none of the values match;
break;
}

example

the user will enter a weekday number( 1 to 7 ) and the program will display the name of the corresponding day

How To Make A Awesome Calender Using HTML,CSS,JQUERY


hello guys , i am going to write here on how to make a calender i am gonna use html and css  first of all you need the codes

you need jquery 1.6.2



jquery ui mouse

How To Add Facebook Share Buttons To Your Website


I wouldn't call this a tutorial but i hope this is helpful for you in some ways in this post I am featuring facebook share buttons.

1 - small icon with text(share on facebook):
<script>
    function fbs_click() {
        u = location.href;
        t = document.title;
        window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436');
        return false;
    }
</script>
<style>
    html .fb_share_link {
        padding:2px 0 0 20px;
        height:16px;
        background:url(http://static.ak.facebook.com/images/share/facebook_share_icon.gif?6:26981) no-repeat top left;
    }
</style>
<a
class="fb_share_link"
href="http://www.facebook.com/share.php?u=%3C;url%3E"
onclick="return fbs_click()"
rel="nofollow"
target="_blank">Share
    on
    Facebook</a>

2 - text(share on facebook)
<script>
function fbs_click() {
    u = location.href;
    t = document.title;
    window.open(
        'http://www.facebook.com/sharer.php?u=' +
        encodeURIComponent(u) +
        '&t=' +
        encodeURIComponent(t),
        'sharer',
        'toolbar=0,status=0,width=626,height=436'
    );
    return false;
}
</script>
<a href="http://www.facebook.com/share.php?u=%3C;url%3E" onclick="return fbs_click()" rel="nofollow" target="_blank">Share
    on
    Facebook</a>

3 - icon(facebook)
<script>
function fbs_click() {
    u = location.href;
    t = document.title;
    window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer',
        'toolbar=0,status=0,width=626,height=436');
    return false;
}
</script>
<style>
html .fb_share_button {
    display: -moz-inline-block;
    display:inline-block;
    padding:1px 20px 0 5px;
    height:15px;
    border:1px solid #d8dfea;
    background:url(http://static.ak.facebook.com/images/share/facebook_share_icon.gif?6:26981) no-repeat top right;
}
html .fb_share_button:hover {
    color:#fff;
    border-color:#295582;
    background:#3b5998 url(http://static.ak.facebook.com/images/share/facebook_share_icon.gif?6:26981) no-repeat top right;
    text-decoration:none;
}
</style>
<a class="fb_share_button" href="http://www.facebook.com/share.php?u=%3C;url%3E" onclick="return fbs_click()" rel="nofollow" style="text-decoration: none;"
target="_blank"></a>

Thanks.

How To Make A Contact Form In PHP

this is a simple contact form that many websites use in their website for a contact for , we can make this with html and php , html is form and php is to send the email.

What Is Pseudocode

Pseudo Code is structured english like way of representing the solution to a problem. it is considered a first draft because pseudocode eventually has to be translated in to a programming language. although pseudo code is like english and has some precision to it,it does not have the very definite precision of a programming language. a computer cannot execute pseudocode , when using pseudocode it is easy to plan a program, concentrate on the logic and do not worry the rules of a specific language most people find that it is more difficult to change the logic


What Is Flowchart

A flowchart is a diagrammatic representation of the processes involved in arriving at a solution to a problem. while many symbols are included in its notation, you can see the most important below

What Is Object Oriented Programming (OOP)

Object oriented programming (oops ) is an emerging major programming paradigm. much of its approach to program and system design is owned to concepts which also gave rise to structured programming , an object is a particular instance of a class and consists, essentially, of data which defines its characteristics and current status together with procedures, or methods , which operates the object

How To Display Time In Javascript

ok this is a simple clock i mean its a digital one but its real time , the javascript is down here