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...

Wordpress Error: Download failed. There are no HTTP transports available which can complete the requested request.


Today I found this error when I tried to update to wordpress version to 4.3.1. Remember, my wordpress was hosted in IIS with Windows Server 2008 R2 Standard. In the past whenever I tried to update the wordpress it worked like charm.
It was very frustrating for me to suddenly receive the error

Download failed. There are no HTTP transports available which can complete the requested request.

On googling I found to uncomment the following extensions from php.ini
  • extension=php_curl.dll
  • extension=php_openssl.dll
Remember, I hosted my blog on windows environment with IIS so I uncommented both extensions from PHP folder (Where PHP is installed) & Windows folder as both of these folders were containing php.ini file. You just have to remove the preceding semi colon, save the file & that’s it you have enable the extension. If you guys know any other method to get rid of this error then please share in the form of comments.
Read more...

Replace empty record in ms sql server

Couple of days ago while working in a project I got requirement to replace empty or we say blank record with space. Remember I am asking to replace the record that doesn’t exist with space, means it’s not related to NULL data, not related to space in column etc.
One more thing which was very strange for me at that time and I want to add it here that you can replace empty record with space by using different possible ways but to retrieve space in front end (Website) most of them doesn’t work and you may surprise that in ms sql server it is returning space but why let's suppose asp.net code is unable to get that space. So the methods work fine for me are listed below
SELECT ISNULL(NULLIF(DATABASE_COLUMN,''),' ')
SELECT ISNULL(DATABASE_COLUMN,' ')
NULLIF returns the first expression if the two expressions are not equal. If the expressions are equal, NULLIF returns a null value of the type of the first expression and if first expression is empty/blank then NULLIF returns a null value of the type of the first expression.

So that’s it. Enjoy your life.
Read more...

Check whether first character in a string is capital or not

In this tutorial we will learn how to check whether first character in a string is capital or not. It’s pretty simple and don’t required any professional coding. Let’s have a look how to do so.
 
string mystring = "Adeel";

if (mystring[0].ToString() == mystring[0].ToString().ToUpper())
{
    Response.Write("First character is capital");
}
else
{
    Response.Write("First character is not capital");
}

So that’s it, this is the proper and simple way.

Happy Coding!!!

Read more...

Make first character of a string upper case in asp.net

Couple of days ago I got requirement of make first character of a string upper case in asp.net. I found but unable to get any built-in function available in .net so after some sort of coding, I develop my own function.
 
public static string MakeFirstCharUpper(string inputstring)
{
    if (String.IsNullOrEmpty(inputstring))
        throw new ArgumentException("ARGH!");
    return inputstring.First().ToString().ToUpper() + String.Join("",inputstring.ToLower().Trim().Skip(1));
}

So that’s it. Just you have to call this function and you will get desired output.

Happy Coding!!!

Read more...

Image printing problem in google chrome


In this article we will look how to fix the image printing problem in Google chrome. Most of the developers complaint that there code snippet for printing content of any div works well in all browsers except chrome, they can see images being printed in all browsers but in Google chrome neither images shown in print preview nor printed. So for Google chrome the workaround is pretty simple, just you have to add the <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\> and that's it. How? Let’s have a look

Image printing problem in Google chrome


        function printcontent() {
            var docType = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"  \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
            var disp_setting = "toolbar=yes,location=no,directories=yes,menubar=yes,";
            disp_setting += "scrollbars=yes,width=800, height=800, left=50, top=25,_blank";
            if (navigator.appName != "Microsoft Internet Explorer")
                disp_setting = "";

            var content_vlue = document.getElementById("divContent").innerHTML;
            var docprint = window.open("", "", disp_setting);
            docprint.document.open();

            docprint.document.write(docType);
            docprint.document.write('<head><title></title>');

            docprint.document.write('</head><body style="padding:0;margin-top:0 !important;margin-bottom:0!important;"   onLoad="self.print();self.close();">');

            docprint.document.write(content_vlue);
            docprint.document.write('</body></html>');
            //document.write(doct + divContent.innerHTML);
            docprint.document.close();
            docprint.focus();
        }

<div id="divContent">
        <table width="100%" cellpadding="2" cellspacing="2">
            <tr>
                <td>
                    <img src="img/web_logo_new.jpg" alt="logo" /></td>
                <td>Some content will come here </td>
            </tr>

        </table>
    </div>
    <input type="button" value="Print" onclick="printcontent();" />

So that's it. Hopefully it will fix your problem of printing images in Google chrome.
Read more...

Difference between Response.Redirect() and Response.RedirectPermanent()

In this asp.net tutorial we will learn the difference between Response.Redirect() and Response.RedirectPermanent(). Microsoft has introduced Response.RedirectPermanent() method in .net 4.0 version. The main objective of this method is to have permanent response redirection to the Search Engines.

Basically Response.RedirectParmanent() is an extension function introduced in .NET 4.0. The main aim of it is to indicate the Response Code to the Search Engine that the page has been moved permanently.

Response.Redirect() is also called 302 temporary redirect. The 302 Temporary redirects are also as they sound; temporary, in which you are telling the search engines to read and use the content of the new page, but to keep checking the original URL first as it will ultimately be reestablished. The Response.Redirect() generates Response code as 302 (Temporary Redirection). If you use the Response.Redirect() to redirect from Page A to Page B, search engines will keep Page A in their index/cache/database since the Response.Redirect() indicates a temporary redirect.

Response.RedirectPermanent() is also called 301 permanent redirect. The 301 permanent redirects are also as they sound; permanently redirects from an old URL to a new one. It also tells the search engines that the old location is to be removed from their index and replaced with the new location. Using 301 redirect is the most search engine friendly way to redirect traffic and search engines. The Response.RedirectParmanent() returns 301 (Permanent Redirection). If you use the Response.RedirectPermanent() to redirect from Page A to Page B, search engines will keep Page B in their index/cache/database since the Response.RedirectPermanent() indicates a permanent redirect and include new page for better performance on search.

Note: Another method used for redirection is Server.Transfer() in which search engine is unaware of any redirection that took place (Status 200) and keep remain the link of old page in its cache/database. Search engine thinks that the old page is producing the output response of the new page.

Read more...

Text search in Stored Procedures in SQL Server 2005 and 2008

In this ms sql server tutorial we will discuss Text search in Stored Procedures in SQL Server 2005 and 2008. There are many ways to accomplish this task. Lets have a look on those methods.
Method 1:
SELECT ROUTINE_NAME, ROUTINE_DEFINITION 
FROM INFORMATION_SCHEMA.ROUTINES 
WHERE ROUTINE_DEFINITION LIKE '%FOO%' 
AND ROUTINE_TYPE='PROCEDURE'
Method 2:
SELECT OBJECT_NAME(ID) 
FROM SYSCOMMENTS 
WHERE [TEXT] LIKE '%FOO%' 
AND OBJECTPROPERTY(ID, 'ISPROCEDURE') = 1 
GROUP BY OBJECT_NAME(ID)
Method 3:
SELECT OBJECT_NAME(object_id)
FROM sys.sql_modules
WHERE OBJECTPROPERTY(object_id, 'IsProcedure') = 1
AND definition LIKE '%FOO%' 

Remember routine_definition is cropped at 4000 chars if you have a long stored procedure. sys.sql_modules doesn't have such restriction.

So that's it. Hopefully you will find this tutorial very handy.
Read more...

Optimize query to count total number of records in a table in ms sql server

In this ms sql server tutorial we will learn how to count total number of records (rows) in a table. Many people use given below query for this purpose
SELECT COUNT(*) AS ROWS FROM MY_TABLE
Let me tell you this query is really a killer query if table contains records more than one lac and worst case is more than one million because this query scans the whole table right from first row to last row.

Now what should we do? What is the optimize query? These are the questions might be coming in your mind, ok, below given is the optimized query that you guys must use for counting records purpose.

SELECT ROWS FROM SYSINDEXES WHERE ID = OBJECT_ID('MY_TABLE') AND INDID < 2
That's it. Hopefully you will find this tutorial very helpful. I love to hear your feedback.
Read more...

Create Fake Query in LINQ to avoid unknown return type error while drag and drop sp in dbml

In this tutorial you will learn how to create Fake Query in LINQ to avoid unknown return type error while drag and drop sp in dbml. Now many of you will be thinking what does it means? Let me explain you, using linq when you drag and drop stored procedure in dbml file and get following alert then it means LINQ is unable to create class of your stored procedure in designer.cs (dbml). unknown return type
When you can face this problem?
  • When you will be selecting columns based on conditions, means in one condition you are getting five columns and in other conditions you are getting seven columns
  • When you will use temporary tables in stored procedure.
  • In string based stored procedure.
Note:-
You can face this problem only in those SPs in which you are retrieving records. So if LINQ will not generate class of your stored procedure then it means you cannot retrieve records.

Steps to get rid of this problem and to create fake query
  • After getting aforementioned error, you have to delete stored procedure from your dbml file.
  • You have to alter SP, comment whole code written in SP, write fake query, in that fake query you have to mention all columns that you want to retrieve in SELECT command in a way illustrated in following picture


Original SP



Comment the original SP, Write Fake Query and Alter the SP

Execute the SP, it will give you result
Once SP is altered with fake query, drag and drop SP again in dbml file, now this time you will not get any error and class of the SP will be created in designer.cs. In the last you have to alter the SP again but this time you will have to revert the whole SP, comment the Fake Query code and bring back the SP into its original state that it has before the Fake Query. After this alteration in SP there is no need to drag and drop it again.



There is one more thing that I will need to discuss with you guys in next post about fake query which is very important. So stay tuned. So that's it. Cheers!!!!
Read more...

Unable to work on visual studio after windows update installed, visual studio close automatically

Hay guys I faced a problem couple of days ago and then I thought it may come to you guys too so that’s why I am publishing this post. Basically when I installed windows 7 in my system and then installed visual studio 2012 in it. Everything was going smoothly and then interval came :) I installed the windows update and when I tried to open the project in visual studio then it was giving me nasty error and closed automatically.
It was very strange situation for me, I quickly came to a point that it happen due to installation of windows update, I goggled my problem and found solution. Solution is pretty simple, just have to install updates of Visual Studio 2012 which is Microsoft Visual Studio 2012 (KB2781514). I went to this link and download the aforementioned visual studio update. Basically that updates contain patch which is patch_KB2781514.exe, you just have to run the exe and once patch successfully install then open the visual studio and do your work :) No need to restart the system.
Read more...

Split string by multiple character delimiter in asp.net

In this article you will learn how to split string by multiple character delimiter in asp.net. Well it is very simple and we can do it by using the built-in split () function of asp.net. Let's have a look on its implementation.
 
        string actualURL = "http://mywebsite.com/aboutus.aspx/images/test.aspx";
        string[] parts1 = actualURL.Split(new string[] { ".aspx" }, StringSplitOptions.None);

So that's it. In this example we have a wrong url containing two pages name and we have to get the first page so we have split the url by ".aspx" delimeter and store the result in parts1 array. 

Another method to do this task is by using Regex
 
string[] parts2 = Regex.Split(actualURL, @".aspx");

Note: Make sure to use using System.Text.RegularExpressions for using Regex.

Happy Coding!!!
Read more...

Calling one stored procedure within another stored procedure in sql

In this article we will learn how to call one stored procedure within another stored procedure in sql. Its quite easier and you don't have to bear any pain to do this. Lets have a look into example given below
declare @studentid bigint
declare @studentname varchar(50) 
set @studentid=20832083
exec @studentname = Web_Proc_GetStudentName @studentid -- use comma to separate multiple parameters 
exec @studentname = Web_Proc_GetStudentName @studentid

The above mentioned line of code is assigning return value of a stored procedure to @studentname variable. So folks that's it. Hope so this article will be proved handy for you.

Stay tuned for more useful tutorials.
Read more...

Get page load time in asp.net using c#

In this article, i will tell you guys how to get page load time. I have a web form that name is getloadtime.aspx, lets suppose there is lot of code written in it due to that its loading speed is very slow, to calculate the load time following code snippet will be used.

getloadtime.aspx.cs

    DateTime ServerStartTime;
    DateTime ServerEndTime;

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected override void OnPreInit(EventArgs e)
    {
        ServerStartTime = DateTime.Now;
        base.OnPreInit(e);
    }

    protected override void OnLoadComplete(EventArgs e)
    {

        ServerEndTime = DateTime.Now;
        TrackPageTime();//It will give you page load time
    }


    public void TrackPageTime()
    {
        TimeSpan serverTimeDiff = ServerEndTime.Subtract(ServerStartTime);
    }


I hope this article will be proved very handy for you people. Enjoy your work, enjoy coding.
Read more...

Problem while exporting numeric data from ms sql server 2008 to excel

In this article i am discussing a problem with you guys that i faced today. Today i run a query in ms sql server 2008 management studio, query was basically giving the following records from student table

  1. Registration_Number
  2. First_Name
  3. Last_Name
  4. Email_Address
Query was

SELECT REGISTRATION_NUMBER,LAST_NAME,FIRST_NAME,EMAIL FROM STUDENT 
ORDER BY FIRST_NAME

Problem was with Registration_Number column, in table its data type was bigint. When i run the that query, copy the result set and then paste into excel then Registration_Number column was giving two problems, mentioned below
  1. Some of registration numbers were in unwanted data type for me such as floating type. I had a registration number 1010512500100483 which was showing as 1.01051E+15
  2. Secondly, some registration numbers were automatically rounded off, such as 1010512500100505 was rounded into 1010512500100500, moreover in excel it was showing as 1.01051E+15 but when I clicked on the cell then it was showing in address bar as 1010512500100500 instead of 1010512500100505
Now we have two solutions, first one is pretty simple in which your excel cell should have been formatted as text before you pasting the result set. 

Before telling you second and accurate solution, let me tell you methods that i adopt in order to paste the actual result set from sql server to excel without changing the cell data type in excel. 

Methods that i adopt and all were proved fail. 

I converted the data type of registration_number column from bigint to varchar as mentioned below but it was not working.
SELECT CONVERT(VARCHAR,REGISTRATION_NUMBER) AS REGISTRATION_NUMBER,LAST_NAME,FIRST_NAME,EMAIL FROM STUDENT 
ORDER BY FIRST_NAME 
I converted the datatype of registration_number column from bigint to varchar and concatenated space as mentioned below but it was not working.
SELECT CONVERT(VARCHAR,REGISTRATION_NUMBER)+' ' AS REGISTRATION_NUMBER,LAST_NAME,FIRST_NAME,EMAIL FROM STUDENT 
ORDER BY FIRST_NAME 
But the following query proved successful as i achieved my target which was copying the query result set and pasting it into excel sheet without formatting any excel cell.
SELECT CONVERT(VARCHAR,REGISTRATION_NUMBER)+CHAR(160) AS REGISTRATION_NUMBER,LAST_NAME,FIRST_NAME,EMAIL FROM STUDENT 
ORDER BY FIRST_NAME 
That's it. Cheers!!!
Read more...

Unable To Drag and Drop Stored Procedure onto dbml Designer

In this article we will discuss about a problem that i faced couple of days ago, my visual studio 2010 was working fine, i closed the visual studio and after some time when i reopened it and try to drag and drop the stored procedure then it didn't allow me to drag and drop the stored procedure.
I tried my level best to reset the settings of visual studio but got no success then by searching on internet i got the solution and the solution is pretty simple, I found that it is due to one of the dll file (dsref80.dll) of visual studio, the dll was corrupted so i straight away took that dll from one of my colleague and replace it

Path to replace the dll is shown below:

C:\Program Files\Common Files\Microsoft Shared\Visual Database Tools\dsref80.dll


Cheerz...! :) 
Read more...

Could not load file or assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified

Today i have got this asp.net nasty error, i fixed it and then decided to share it with you people. I was working on a website developed in asp.net version 2.0 but when i tried to run it through my friend's system (i had given a copy of website to him) then face this error.
To fix this error i simply installed asp.net ajax in that system and website come to life.

To solve issue without installing AJAX.NET:

Copy AjaxControlToolkit.dll and AjaxControlToolkit.pdb version 1.0.61025.0 from my system (in which asp.net ajax is installed) to ASP.NET App bin folder of my friend's system.

(i install my AjaxControlToolkit in C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\AjaxControlToolkit)

Copy System.Web.Extensions.dll (C:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions) and System.Web.Extensions.Design.dll (C:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions.Design) from my system to ASP.NET App bin folder of my friend's system.

Run the website and it's working fine.
Read more...