ASP.NET (35) SQL (25) JAVASCRIPT (24) HTML (14) STYLE SHEET (6) ASP (4) SCRIPT (1)

Search me out HERE!!

Importing a CSV file into your database with SQL Server Management Studio

While bulk copy and other bulk import options are not available on the SQL servers, you can import a CSV formatted file into your database using your SQL Server Management Studio.

You first need to create a table in your database in which you will be importing the CSV file. After the table is created, follow the steps below.
  1. Log into your database using SQL Server Management Studio
  2. Right click on your database and select Tasks -> Import Data
  3. Click the Next > button
  4. For the Data Source, select Flat File Source. Then use the Browse button to select the CSV file. Spend some time configuring how you want the data to be imported before clicking on the Next > button
  5. For the Destination, select the correct database provider (e.g. for SQL Server 2012, you can use SQL Server Native Client 11.0).  Enter the Server name; check Use SQL Server Authentication, enter the User name, Password, and Database before clicking on the Next > button
  6. On the Select Source Tables and Views window, you can Edit Mappings before clicking on the Next > button
  7. Check Run immediately and click on the Next > button
  8. Click on the Finish button to run the package

NULLIF and ISNULL in SQL

ISNULL
Syntax: ISNULL(expression, value)
Explanation: This function will check expression value and if expression is NULL then it will replace it will given value.
Example: SELECT ISNULL(Income,0) AS Income FROM EmpDetail
Here if Income is NULL for any employee then it will return as 0.

NULLIF
Syntax: NULLIF(expression, value)
Explanation: This function will check expression value and if expression = value then it will replace it with NULL (This function is opposite of ISNULL).
Example: SELECT NULLIF(Income,0) AS Income FROM EmpDetail
Here if Income is 0 for any employee then it will return as NULL.

Disable right click on web page using JQuery

Use below JQuery code to disable right click on web page. This will work well on all browser (IE, Firefox, Google chrome).

// To prevent right click
$(document).bind('contextmenu', function (e) {
        e.preventDefault();
        return false;
});

 

Disable saving web page with CTRL-S using JQuery

Use below JQuery code to disable saving web page using "CTRL-S" keyword directly. This will work well on all browser (IE, Firefox, Google chrome).

// To prevent saving web site directly using "ctrl-s"
$(document).bind('keydown keypress', 'ctrl+s', function () {
        $('#save').click();
        return false;
    });

Take backup of Single Table in SQL Server and MySql

Using below query, you can take backup of table in SQL Server:
SELECT * INTO [NewTableName] FROM [BackupTable]

Using below query, you can take backup of table in MySql:
CREATE TABLE [NewTableName] SELECT * FROM [BackupTable]

Getting selected value from RadioButtonList in Javascript


Consider below ASP.Net RadioButtonList control:
<asp:RadioButtonList ID="rbList" runat="Server">
   <asp:ListItem Text="Kapil" Value="1" Selected="True">
   <asp:ListItem Text="Baheti" Value="2">
</asp:RadioButtonList>

You can now get selected radio button value using below javascript:
function GetRadioButtonValue()
{
  var id = <%= rbList.ClientID %>;
  var radio = document.getElementsByName(id);
  for (var i = 0; i < radio.length; i++)
     {
        if (radio[i].checked)
           alert(radio[i].value);
     }
}

Insert multiple rows together in table in SQL Server

You can insert multiple rows together in table in SQL Server using below 3 methods:

CREATE TABLE Test (ID INT, Value VARCHAR(100));

1. INSERT INTO Test (ID, Value) VALUES (1, 'One');
    INSERT INTO Test (ID, Value) VALUES (2, 'Two');
    INSERT INTO Test (ID, Value) VALUES (3, 'Three');

2. INSERT INTO Test (ID, Value)
    SELECT 1, 'One'
    UNION ALL
    SELECT 2, 'Two'
    UNION ALL
    SELECT 3, 'Three';

3. INSERT INTO Test (ID, Value)
    VALUES (1, 'One'), (2, 'Two'), (3, 'Three');