How to remove a column from a table using JQuery

Sometimes you may get requirement to remove a column from a table or you may want to hide a column from a table. In both cases the logic is same just we have to use the .remove() method if we are interested to remove the column or use the .hide() method if we are interested to hide the column. Let’s have a look on how to do so
Row 2 Cell 1 Row 2 Cell 2
Row 3 Cell 1 Row 3 Cell 2
I want to remove the whole column whenever user click on Remove Button image, let see how we can do this in JQuery
$("#removeButton ").click(function() {
    var $td = $(this).closest("td");
    var index = $td.index() + 1;
    $td.closest("table").find("td:nth-child(" + index + ")").remove();
});
Hopefully it will work for you.

Read more...

How to convert small month name into complete month name in asp.net using c#

Today I checked the code of my team mate who was picking month name from database but there was a problem and to rectify it he was using multiple IF Statements. The problem of month name was with its data type which was string & also it was small month name which means instead of January it was Jan & instead of February it was Feb.
The code he was using to convert small month name into complete month name was something like that

if(monthname==”Jan”)
{
monthname=”January”;
}

For each month he was using IF Statement & then I tried to optimize the code. Following logic I used to convert the nasty IF statements into optimized code.

using System.Globalization;
string monthName = obj[0].month_come_from_database;
string completeMonthName = Convert.ToDateTime(monthName + " 01, 1900").ToString("MMMM", CultureInfo.InvariantCulture);
That’s it. It will always provide complete month name. Hopefully it will work for you. Happy Coding.

Read more...

UPDATE from SELECT in SQL Server

Normally people think UPDATE statement runs only for a single table but for scenario when we have to check multiple values in a multiple table then we cannot use update statement. Well folks it’s just a myth & we can use it while joining multiple tables.
Please check given below sample query to update the records while joining multiple tables
UPDATE
    T
SET
    T.col1 = OT.col1,
    T.col2 = OT.col2
FROM
    Some_Table T
INNER JOIN
    Other_Table OT
ON
    T.id = OT.id
WHERE
    T.col3 = 'some value'
Hopefully it will work for you. Cheers

Read more...

Count total number of columns in a table in sql server

Today we will check how to count total number of columns in a table in sql server. Sometimes we need to compare the columns of one table on multiple servers to get idea if anything is missing or not. It’s better to query the database rather than manually count it.
Its quite simple
SELECT COUNT(COLUMN_NAME)as [Total Columns] FROM INFORMATION_SCHEMA.COLUMNS WHERE 
TABLE_CATALOG = 'database_name_will_come_here' -- IF YOU WANT TO QUERY ANY OTHER DATABASE
AND TABLE_SCHEMA = 'dbo'
AND TABLE_NAME = 'table_name_will_come_here'

That's it. Hopefully it will work for you.

Read more...