Saturday 12 November 2011

How to Print Star in C#

Write the program in C# for print the
                  *
                 **
                ***
               ****
              *****
----------------------------------------
the program is ..
using System;


    class Class1
    {

        static void Main()
        {

            Console.WriteLine("Enter the value for print  the star ");

            int k = int.Parse(Console.ReadLine());

            int n = k - 1;

            int x = 2 * n + 1;

            for (int p = 0; p <= n; p++)
            {

                for (int j = k - 1; j >= 0; j--)
                {

                    Console.Write(" ");

                }

                for (int i = 0; i <= (x - 2 * (k - 1)); i++)
                {

                    if (i % 2 == 1)
                    {

                        Console.Write("*");

                    }

                    else
                    {

                        Console.Write(" ");

                    }

                }

                Console.WriteLine();

                k--;

            }

            Console.ReadLine();

        }

    }
Hope this will help you
Thanks
ROHIT SRIVASTVA




Tuesday 8 November 2011

How to upload file in Server fron client side

Hi guys some time question arise that how to upload image on server.

there are two technique

1. upload image in sqlserver which is not in actual form it is in byte form .

2. upload image path in SQL Server and image is upload in Server .

here we write the code for upload file in server and path save in sql server

Database structure :
========================================================================
Create Database uploadfile

use uploadfile

Create table upload
(
id int identity(1,1),
imgpath varchar(100)
)

Now Create the Store Procedure ..

Create proc usp_ins_uploadfile
@path varchar(100)
AS
insert into upload values(@path)

========================================================================

Lets start the code open the new website make the folder where u want to save your file or image.i make the folder which name is uploadfile .

below is the design part

<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<asp:FileUpload ID="fupUpload" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
</td>
</tr>
</table>

</div>
</form>

in above there are file upload control and one submit button .
-----------------------------------------------------------------------------
below is the cs code

private string path = HttpContext.Current.Request.PhysicalApplicationPath + "uploadfile";
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnSubmit_Click(object sender, EventArgs e)
{
#region
//this code is used for the save the image
Random randomno = new Random();
int imageid1 = randomno.Next(0, 1000000);
string strpic = fupUpload.FileName;
if (strpic != "")
{
ViewState["logopath1"] = imageid1.ToString() + fupUpload.FileName.ToString();
fupUpload.PostedFile.SaveAs(path + "/" + ViewState["logopath1"]);
}
else
{
ViewState["logopath1"] = "";
}
#endregion
#region *this code is upload the file path in Server*
int result = 0;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["myCon"].ToString());
SqlCommand cmd = new SqlCommand("usp_ins_uploadfile", con);
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@path", ViewState["logopath1"]);
result = cmd.ExecuteNonQuery();
if (result > 0)
{

}
else
{

}
#endregion
}

Description: In this code i declare the path which have the server path . after that wirte the code in button submit click .
firstly we genrate the random no this is because if file name is same then it override the file or image .
for example we upload image which name is rohit.png then fine this is save into our application folder .
but when again we upload another file or image which name is same like rohit.png then it replace the
previous image or file.in this code i divide the code in two part first region is save the data in folder
and second one is save the path in the database .

Hope this will help you
ROHIT SRIVASTAVA

Friday 4 November 2011

Computer Magic

Go to google.com and type below line . see what happen 
do a barrel roll
and press enter.
===========================================
2.
Open Microsoft Word and type

=rand (200, 99)

And then press ENTER
Then see the magic...

3.. Go to Goolgle and type TILT and Press enter 
see the magic

hope you have learn something new 
Thanks 
ROHIT SRIVASTVA
 

Saturday 22 October 2011

Web config file in ASP .net

Description of web config file :
Web.config file  is a configuration file for the Asp .net web application. An Asp .net application has one or more web.config file which keeps the configurations required for the corresponding application. 
Web.config file is written in XML with specific tags having specific meanings.
Some point in Web Config File:
A web Application can contain more than one web config file .and it reside  different sub-directories of your web application. Web config file in sub-directory take precedence over the setting that are specified in the  parent directory .
2. web config file protected by the IIS. so clients can not get to them. if u try to retrive an existing http:hellohome.com/webconfig then u will get Access denied or error .
3.When you modify the settings in the Web.Config file, you do not need to restart the Web service for the modifications to take effect.. By default, the Web.Config file applies to all the pages in the current directory and its subdirectories.
-----------------------------------------------------------------------------------------
The web config is XML file it can consist of any valid xml tags but the root element always be <configuration>

some tag description

1.The <configuration> tag has child tag, which we call section group, the <system.web> tag. A section group typically contains the setting sections, such as: compilation, customErrors, authentication, authorization, etc. The way this works is pretty straightforward: you simply include your settings in the appropriate setting sections. You want to use a different authentication mode for your Web application, you'd change that setting in the authentication section.

2.<authentication>

The authentication section controls the type of authentication used within your Web application, as contained in the attribute mode. You'll enter the value "None" if anyone may access your application. If authentication is required, you'll use "Windows", "Forms" or "Passport" to define the type of authentication. For example:

<authentication mode="Windows" />

3.<authorization>

To allow or deny access to your web application to certain users or roles, use <allow> or <deny> child tags.

<authorization>
<allow roles="Administrators,Users" />
<deny users="*" />
</authorization>

It's important to understand that ASP.NET's authorization module iterates through the sections, applying the first rule that corresponds to the current user. In this example, users carrying the role Administrators or Users will be allowed access, while all others (indicated by the * wildcard) will encounter the second rule and will subsequently be denied access.

4.<compilation>

Here, you can configure the compiler settings for ASP.NET. You can use loads of attributes here, of which the most common are debug and defaultLanguage. Set debug to "true" only if you want the browser to display debugging information. Since turning on this option reduces performance, you'd normally want to set it to "false". The defaultLanguage attribute tells ASP.NET which language compiler to use, since you could use either Visual Basic .NET or C# for instance. It has value vb by default.

5.<customErrors>

To provide your end users with custom, user-friendly error messages, you can set the mode attribute of this section to On. If you set it to RemoteOnly, custom errors will be shown only to remote clients, while local host users will see the ugly but useful ASP.NET errors -- clearly, this is helpful when debugging. Setting the mode attribute to Off will show ASP.NET errors to all users.

If you supply a relative (for instance, /error404.html) or absolute address (http://yourdomain.com/error404.html) in the defaultRedirect attribute, the application will be automatically redirected to this address in case of an error. Note that the relative address is relative to the location of the Web.config file, not the page in which the error takes place. In addition you can use <error> tags to provide a statusCode and a redirect attribute:

<customErrors mode="RemoteOnly" defaultRedirect="/error.html">
<error statusCode="403" redirect="/accessdenied.html" />
<error statusCode="404" redirect="/pagenotfound.html" />
</customErrors>

Friday 21 October 2011

Print triangle without for loop

  class Program
    {
        static void Main(string[] args)
        {

            int i = 1;
        A: if (i < 7)
            {
                pro(i);
                i++;
                goto A;
            }
            int l = 6;
        D: if (l > 0)
            {
                pro1(l);
                l--;
                goto D;

            }

            Console.Read();
        }

        protected static void pro(int j)
        {
            int k = 1;
        B:
            if (k < j)
            {
                Console.Write(k);

                k++;
                goto B;
            }
            Console.WriteLine();

        }

        protected static void pro1(int j)
        {
            int k = 1;
        C:
            if (k < j)
            {
                Console.Write(k);

                k++;
                goto C;
            }
            Console.WriteLine();

        }
    }

out put is
1
12
123
1234
12345
12345
1234
123
12
1

Thursday 20 October 2011

What is the Partial Class in C#

Partial Class:

How to find nth highest salary

Question : normally this question asked that write the query for nth highest sal ?
Answer: u use any one of them
1.    select distinct a.salary from Salary a where 5=( select count(distinct b.salary) from Salary b where     a.salary<=b.salary)
------------------------------------------------------
2. Select top 1 salary from (
  
Select Distinct top n salary
    from
employee
    order
by  salary desc) a
    order by
salary

---------------------------------------
3.SELECT distinct salary FROM
(
    SELECT DENSE_RANK() OVER (ORDER BY salary DESC) AS rank, salary
    FROM property_R
) T2
WHERE rank=1 

Wednesday 19 October 2011

Convert String

my data return string (always 9 character) as following,
000005330
000004110
000041660
how my GridView display above value into decimal. the expected result as following,
53.30
41.10
416.60
------------------------
Sample solution
  string a = "000005330";

            a = a.Insert(a.Length - 2, ".");

            float num = float.Parse(a);

Friday 14 October 2011

"Diffence between Delete And truncate in SQL Server"

Delete :
1. Delete is DML command  .
2. We can use where condition in Delete.
3. Delete retain the identity.
4. Slower then truncate because it keep logs
5.Triggers get fired in DELETE command
6. DELETE you can rollback data .
7. It deletes specified data if where condition exists
----------------------------------------------------------------------------
Truncatre:
1. Delete is DDL Command.
2. We can not use where condition in truncate .
3. If the table contains an identity column, the counter for that column is reset to the seed value that is defined for the column
4. Faster in performance wise, 
5. Triggers not fired in truncate command
6. It cannot rollback data(but it is possible).
7. It delete all data.
----------------------------------------------------------------------------
Question :TRUNCATE is much faster than DELETE.
Reason:When you type DELETE.all the data get copied into the Rollback Tablespace first.then delete operation get performed.Thatswhy when you type ROLLBACK after deleting a table ,you can get back the data(The system get it for you from the Rollback Tablespace).All this process take time.But when you type TRUNCATE,it removes data directly without copying it into the Rollback Tablespace.Thatswhy TRUNCATE is faster.Once you Truncate you cann't get back the data.
----------------------------------------------------------------------------------------------
Question : How to rollback the data when delete command execute?

Answer:
CREATE PROCEDURE [usp_delete_Pataint_master]
 (@PataintID [int],
 @BranchID [int]

)
AS
 BEGIN
 SET NOCOUNT ON
  BEGIN TRAN

  DELETE [dbo].[Pataint_master]
  WHERE ([BranchID] = @BranchID
  AND [PataintID]  = @PataintID)
  IF @@ERROR = 0
   COMMIT TRAN
  ELSE
   ROLLBACK TRAN
  RETURN (@@ERROR)
 END

GO

Saturday 8 October 2011

When use Array and when use ArrayList


Arrays are strongly typed, and work well as parameters. If you know the length of your collection and it is fixed, you should use an array.
ArrayLists are not strongly typed, every Insertion or Retrial will need a cast to get back to your original type. If you need a method to take a list of a specific type, ArrayLists fall short because you could pass in an ArrayList containing any type. ArrayLists use a dynamically expanding array internally, so there is also a hit to expand the size of the internal array when it hits its capacity.

Hope this will help you
Thanks
Rohit Srivastava

How to convert ArrayList to Array


Question arises that how to convert array list to array . below are simple code to convert Arraylist to array
Simple Answer are given below
using System;
using System.Collections;


class Program
{
    static void Main()
    {
        ArrayList arrList = new ArrayList();


        int[] arrToConvert = new int[] {};


        //Add some value to ArrayList of type integer


        arrList.Add(1);


        arrList.Add(2);


        arrList.Add(3);


        arrList.Add(4);


        //Now convert ArrayList to array


        arrToConvert = (int[])arrList.ToArray(typeof(Int32));


        foreach(int i in arrToConvert )
        {
            Console.WriteLine(i);
            
        }
     
            Console.ReadLine();
    }
}


Array List

Question: Describe the Array List ?
Question : What is difference between Array and Arraylist.
Ans: Below full Description of Array list
Firstly i want to describe why use array list

 The main problem of simple array is that their size is fixed by the number you specify when declaring the array variable: you cannot add items beyond the specified dimension. Another limitation is that you cannot insert an item inside the list. To overcome this, you can create a linked list. Instead of working from this, the .NET Framework provides the ArrayList class. With the ArrayList class, you can add new items to a list, insert items inside a list, arrange items of a list, check the existence of an item in a list, remove an item from the list, inquire about the list, or destroy the list. These operations are possible through various properties and methods.
The ArrayList class is defined in the System.Collections namespace. To use it, first declare a pointer to ArrayList
Simple definition of Array list is 
An ArrayList is an array that can dynamically grow and shrink.
Method In Array list 
Add Method :
using System.Collections;
class Program
{
    static void Main()
    {
 // Create an ArrayList and add four element elements.
 ArrayList list = new ArrayList();
 list.Add("One");
 list.Add("Two");
 list.Add("Three");
list.Add("Four")
}
}
these program add the four elemnet in Arraylist 
Ex:Call the method in which parameter of this method is Array list
using System;
using System.Collections;
class Program
{
    static void Main()
    {
 // Create an ArrayList and add three method 
 ArrayList list = new ArrayList();
 list.Add(5);
 list.Add(7);
list.Add(11);
 // Use ArrayList with method.
 Example(list);
    }
    static void Example(ArrayList list)
    {
 foreach (int i in list)
 {
     Console.WriteLine(i);
 }
    }
}
=========

Output
5
7
11
Add one ArrayList to second one
using System;
using System.Collections;
class Program
{
    static void Main()
    {
 // Create an ArrayList with two values.
 ArrayList list = new ArrayList();
 list.Add(5);
 list.Add(7);
 // Second ArrayList.
 ArrayList list2 = new ArrayList();
 list2.Add(10);
 list2.Add(13);
 // Add second ArrayList to first.
 list.AddRange(list2);
 // Display the values.
 foreach (int i in list)
 {
     Console.WriteLine(i);
 }
    }
}
Output
5
7
10
13
Description of the two ArrayLists. The first ArrayList has two elements added
to it.Next,the second ArrayList has two elements added to it. The second ArrayList is then appended to the first using the AddRange method. The example finally show
the output.

Count and Clear

The ArrayList class provides the Count property, which is a virtual property. When you use Count, no counting is actually done; This means that Count is fairly fast. The example also shows Clear.
using System;
using System.Collections;
class Program
{
    static void Main()
    {
 // Create an ArrayList with three values.
 ArrayList list = new ArrayList();
 list.Add(9);
 list.Add(10);
list.Add(20);
 // Show number of elements in ArrayList.
 Console.WriteLine(list.Count);
 // Clear the ArrayList.
 list.Clear();
 // Show count again.
 Console.WriteLine(list.Count);
    }
}
Output
3
0
Description:
Count. The Count property returns an int, and you can say that it will always be a positive value.
Clear. You can call the method Clear on your ArrayList. Internally, this calls the Array.Clear method.

ArrayList Sort and Reverse

using System;
using System.Collections;
class Program
{
    static void Main()
    {
 // Create an ArrayList with five strings.
 ArrayList list = new ArrayList();
 list.Add("Cat");
 list.Add("Zebra");
 list.Add("Dog");
 list.Add("Cow");
list.Add("lion")
 // Sort the ArrayList.
 list.Sort();
 // Display the ArrayList elements.
 foreach (string value in list)
 {
     Console.WriteLine(value);
 }
 // Reverse the ArrayList.
  list.Reverse();
  // Display the ArrayList elements again.
  foreach (string value in list)
 {
     Console.WriteLine(value);
 }
    }
}

Output
Cat
Cow
Dog
Lion
Zebra

Zebra
Lion
Dog
Cow
Cat
Description:

Implementation:

Inside the base class libraries, you can see that the Sort method here always

ends up in an internal TrySZSort or QuickSort method when it doesn't throw an exception. The TrySZSort internal method is optimized for one-dimensional arrays, also known as "Zero" arrays or vectors.
Performance of Sort. Because the TrySZSort method used in the base class libraries is implemented in native code, it has been heavily optimized. Therefore, this method is likely faster than any solution written in the C# language. In other words: using Sort on ArrayList or on Array is faster than most custom implementations.

Insert and remove elements

using System;
using System.Collections;

class Program
{
    static void Main()
    {
 // Create an ArrayList with four strings.
 ArrayList list = new ArrayList();
 list.Add("Dot");
 list.Add("Net");
 list.Add("Perls");
list.Add("VB.Net");
        // Remove middle element in ArrayList.
 list.RemoveAt(1); // It becomes [Dot, Perls,Vb.Net]
 
 // Insert word at beginning of ArrayList.
 list.Insert(0, "Carrot"); // It becomes [Carrot, Dot, Perls,VB.Net]
 // Remove first two words from ArrayList.
 list.RemoveRange(0, 2);
 
 // Display the result ArrayList.
 foreach (string value in list)
 {
     Console.WriteLine(value); // <-- "Perls"
 }
    }
}

Output
Perls
Vb.Net

Loop with for

using System;
using System.Collections;
class Program
{
    static void Main()
    {
 // Create an ArrayList with four strings.
 ArrayList list = new ArrayList();
 list.Add("man");
 list.Add("woman");
 list.Add("plant");
list.Add("animals")
 // Loop over ArrayList with for.

 for (int i = 0; i < list.Count; i++)
 {
     string value = list[i] as string;
     Console.WriteLine(value);
 }
    }
}

Output

man
woman
plant
animal
Using "as" cast with ArrayList elements. The "as" cast in C# is probably the best way to cast reference types such as string. After you cast, you can check the result for null before using the variable, to see if the cast succeeded. This is not always needed.

Get range of values

using System;
using System.Collections;

class Program
{
    static void Main()
    {
 // Create an ArrayList with 4 strings.
 ArrayList list = new ArrayList();
 list.Add("fish");
 list.Add("amphibian");
 list.Add("bird");
 list.Add("plant");
 // Get last two elements in ArrayList.
 ArrayList range = list.GetRange(2, 2);
// Display the elements.
  foreach (string value in range)
 {
     Console.WriteLine(value); // bird, plant
 }
    }
}

Output

bird
plant
Hope This will help you 
Difference Between Array and ArrayList
  • Array is: a datatype, thatcan be used by calling indexes. during runtime, one cannot really change the size of the array, unless you use the method of copying the array and getting rid of the old one. In .NET, the Visual Studio makes use of a special class to store the data. Because of this, the performance is actually quite fast. This is also because in an array, you need to specify the size and thus, the data is stored one after the other.
  • Examples:  
      • int[ ] myNumbers= new int[5];
    • myNumbers[0] = 16;
  • ArrayList is: a datatype collection. In order to fill an ArrayList, one can use the .Add property. ArrayLists are very dynamic in the sense that when you add and/or remove items from it, the performace stays the same. The internal structure of an ArrayList is an array.
  • Examples:
    • ArrayList myArray = new ArrayList();
    • myArray .Add(“Steph”);
    • string str = myArray [0];
Most of the time, we tend to choose array lists rather than arrays since we have no idea how big it is going to turn out. Arrays are ideal when you know how many items you are going to put in it. Whenever possible, it is recommended to use arrays as this drastically improves the performance.
ARRAY
ARRAYLIST
1. Char[] vowel=new Char[]; ArrayList a_list=new ArrayList();
2. Array is in the System namespace ArrayList is in the System.Collections namespace.
3. The capacity of an Array is fixed ArrayList can increase and decrease size dynamically
4. An Array is a collection of similar items ArrayList can hold item of different types
5. An Array can have multiple dimensions  ArrayList always has exactly one dimension
Thanks 
Rohit Srivastava


Friday 7 October 2011

How to reset the identity column

Generally when we create a table and set identity and insert the data for testing purpose  but when we delete the data and feed original data then identity start with last not start with 1.
Here is solution
lets we create the table

create table ABC
(
id int identity(1,1),
name varchar(30)
)

and insert some data

insert into abc values ('ROHIT')
insert into abc values ('Riya')
insert into abc values ('Ankita')
insert into abc values('Kumar')
insert into abc values('baby')

and then select the data then output is like below


Select * from abc


1 ROHIT
2 Riya
3 Priya
4 Kumar
5 baby

but when we delete data from table abc and after that insert some data then it started with 6 id not 1
so to achieve this we use following query
after the delete command
delete from abc
we use the below query
DBCC CHECKIDENT (abc, RESEED, 0)
note : where abc is the table name
after this when we start enter the data then id start with 1 not 6

Hope this will help you if any problem then please let me know

Thanks
ROHIT SRIVASTAVA


Monday 26 September 2011

How to Refresh Parent Page

Question : The Question arise that . i have a data control and i click on this template then an window open offcourse this is the child window and we show some data on this child window . i want refresh the parent page after load the child window .How to do this
Answer:
lets take an example what you want simply when user see her/his mail then after clicking the mail the row color is chage . Exactly we want this in your project .. So there are a solution ..
write the following code on your child window page laod  or where you want

const string cRefreshParent = "<script language='javascript'>" +

    "  window.opener.document.forms(0).submit();" + "</script>";
    const string cRefreshParentKey = "RefreshParentKey";
    if (!this.Page.ClientScript.IsClientScriptBlockRegistered(cRefreshParentKey))
    {
        this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
        cRefreshParentKey, cRefreshParent);
    }

I think   this solution is quite easy but very useful if you want to create Web applications in which  open child window and you want to refersh parent page.

Friday 9 September 2011

Difference Between Dll and EXE

This  question is genrally asked in interview and the answer is
DLL:
1)it is not self executable
2)it runs in application process memory
3)it has no entry point
4)it is reusable
5)Out Process Server

Exe:
1)it is self executable
2)it runs in own memory
3)it have main function(Entry point)
4)it is self executable
5) In Process Server
-------------------------------
Some differnce related to Space
DLL file is a Library File which supports a executable file.
DLL stands for Dynamic Link Library - it is a library file which is linked at runtime (ie. dynamically) rather than at compile-time.an exe has its own individual address space, whereas a dll have one address space, thus it can be shared.A dll can be "dynamically" loaded and unloaded from memory, allowing an application to take up less space than it normally would when its not using the functions in that dll.
-----------------------------------------------------------------------------------

when we read above differnce then there are one Question what is IN process server and out process server 
then the answer is
  • Out-of-process server components. Out-of-process server components are always EXE files.
  • In-process server components. In-process server components are always DLL files.
The difference between these server component types is with respect to the client application.
When a server component runs out-of-process with respect to its client, it has the following characteristics:
  • It can run as a standalone application completely apart from the client.
  • It does not share the same address space under the operating system.
When a server component runs in-process with its client, it has these important features:
  • The server component and client share the same executable space under the operating system.
  • The server component and client share some of the same memory.
As you might imagine, there are pros and cons to both in-process and out-of-process server components.
----------------------------------------------------------------------------------------------
In process server:A library (DLL) running in the same process space as the client, for example, an ActiveX control embedded in a Web page viewed under Internet Explorer or Netscape. Here, the ActiveX control is downloaded to the client machine and invoked within the same process as the Web browser.The client communicates with the in-process server using direct calls to the COM interface.

Out process server:Another application (EXE) running in a different process space but on the same machine as the client. For example, an Excel spreadsheet embedded in a Word document are two separate applications running on the same machine.The local server uses COM to communicate with the client.

Thursday 8 September 2011

union and union all in SQL Server

Which  is faster UNION ALL or UNION?
Firstly we have to know that what is union

Combines the results of two or more queries into a single result set that includes all the rows that belong to all queries in the union. The UNION operation is different from using joins that combine columns from two tables.
The following are basic rules for combining the result sets of two queries by using UNION:
  • The number and the order of the columns must be the same in all queries.
  • The data types must be compatible.
    (from msdn) 



    lets come to our concern question the answer is

    UNION ALL faster than a UNION because for union operation server needs to remove the duplicate values but for union all its not. Thats why the UNOIN ALL is fater than UNION Operation. It is recommended that if you know that the union set operation never returns duplicate values than you must use UNION ALL instead of UNION.


Story of Appreciation

One young academically excellent person went to apply for a managerial position in a big company.

He passed the first interview, the director did the last interview, made the last decision.

The director discovered from the CV that the youth's academic achievements were excellent all the way, from the secondary school until the postgraduate research, never had a year when he did not score.

The director asked, "Did you obtain any scholarships in school?" the youth answered "none".

The director asked, " Was it your father who paid for your school fees?" The youth answered, "My father passed away when I was one year old, it was my mother who paid for my school fees.

The director asked, " Where did your mother work?" The youth answered, "My mother worked as clothes cleaner. The director requested the youth to show his hands. The youth showed a pair of hands that were smooth and perfect.

The director asked, " Have you ever helped your mother wash the clothes before?" The youth answered, "Never, my mother always wanted me to study and read more books. Furthermore, my mother can wash clothes faster than me.

The director said, "I have a request. When you go back today, go and clean your mother's hands, and then see me tomorrow morning.*

The youth felt that his chance of landing the job was high. When he went back, he happily requested his mother to let him clean her hands. His
mother felt strange, happy but with mixed feelings, she showed her hands to the kid.

The youth cleaned his mother's hands slowly. His tear fell as he did that. It was the first time he noticed that his mother's hands were so wrinkled, and there were so many bruises in her hands. Some bruises were so painful that his mother shivered when they were cleaned with water.

This was the first time the youth realized that it was this pair of hands that washed the clothes everyday to enable him to pay the school fee. The bruises in the mother's hands were the price that the mother had to pay for his graduation, academic excellence and his future.

After finishing the cleaning of his mother hands, the youth quietly washed all the remaining clothes for his mother.

That night, mother and son talked for a very long time.

Next morning, the youth went to the director's office.

The Director noticed the tears in the youth's eyes, asked: " Can you tell me what have you done and learned yesterday in your house?"

The youth answered, " I cleaned my mother's hand, and also finished cleaning all the remaining clothes'

The Director asked, " please tell me your feelings."

The youth said, Number 1, I know now what is appreciation. Without my mother, there would not the successful me today. Number 2, by working together and helping my mother, only I now realize how difficult and tough it is to get something done. Number 3, I have come to appreciate the importance and value of family relationship.

The director said, " This is what I am looking for to be my manager.
I want to recruit a person who can appreciate the help of others, a person who knows the sufferings of others to get things done, and a person who would not put money as his only goal in life. You are hired.

Later on, this young person worked very hard, and received the respect of his subordinates. Every employee worked diligently and as a team. The company's performance improved tremendously.
---------------------------------
this is the heart toching story for me i dont know were i read this story but i like very much so i put there

Thanks
Rohit Srivastava





Wednesday 7 September 2011

SQL Server Query

Here are the test table in which there are two field

create table  test
(
name varchar(30),
id varchar(30)
)

insert into test values('A1')

name              id
A                  1
B                 2
C                  3
C                 4
A                   2
A                   3
-------------------------
and i want to result  like below

A     1, 2, 3
B     2
C     3, 4

below query will help u as a tonic
SELECT [name], STUFF((SELECT ', ' + [id]
                       FROM test  T2
                          WHERE T1.[name] = T2.[name]
                      Order By [id]
                FOR XML PATH('')),1,1,'') AS [Subject Books]
           FROM test T1
           GROUP BY [name]


-----------------------------
Hope this will help you
Thanks
Rohit Srivastava

Tuesday 6 September 2011

Update Specific Field Value in SQL Server

How to Update Some Specific Value IN Sql Server

UPDATE tblLocation SET LocationName = REPLACE(LocationName,'hall','Hall');
it can easily understand by Below example
lets my table name is Party
id  PartyName                       active
1    Rohit                                   1
2    Dealer Rohit                              1
3    Owner                                1
4    Builder Rohit                              1
-----------------------------
in above we want to update partyname field value where ROHIT replace to Riya then query is

UPDATE Party  SET PartyName= REPLACE(PartyName,'Rohit','Riya');
---------------------------------------------------------------------------------------
2..Another Query
How to Update First Word Is Always Capital  in SQL Server..
To Acompolish this we create a function and call this like below

 CREATE FUNCTION [dbo].[properCase](@string varchar(8000)) RETURNS varchar(8000) AS
BEGIN 
    SET @string = LOWER(@string)
    DECLARE @i INT
    SET @i = ASCII('a')
    WHILE @i <= ASCII('z')
    BEGIN
        SET @string = REPLACE( @string, ' ' + CHAR(@i), ' ' + CHAR(@i-32))
        SET @i = @i + 1
    END
    SET @string = CHAR(ASCII(LEFT(@string, 1))-32) + RIGHT(@string, LEN(@string)-1)
    RETURN @string
END

 And Call this function like this  in ur Query

 UPDATE urTable SET name=[dbo].[properCase](name)

this set first letter of ur word is capital and other is Small , According to Ur Requirement

Hop This will help u
Rohit Srivastava

How to check string value is number or not

Hi friends there are the simple javascript method for this
string number = "100";
if (number.All(Char.IsDigit))
{
Console.Write("{0} is a valid number!", number);
}
else
{
Console.Write("{0} is not a valid number!", number);
 } 
 ----------------------------------------------------------
Hope this will help you 
thanks 
Rohit Srivastava

Monday 5 September 2011

Set Focus On Text Box when Page Load

Hi Question arises in our mind is how to default focus to a asp control when the page loads  . First way is use the javascript other is given below
  This is another extremely simple thing that can be done without resorting to writing JavaScript.  If you only have a single textbox (or two) on a page why should the user have to click in the textbox to start typing?  Shouldn't the cursor already be blinking in the textbox so they can type away?
Using the DefaultFocus property of the HtmlForm control you can easily do this.
<body>
  <form id="frm" DefaultFocus="txtUserName" runat="server">
    <!--Write your page code here-->
  </form>
</body>

Hope this will benificail for all

Maintain Scroll Position in ASP .net

Hi there are a Question to  maintain the position of the scrollbar on postbacks. In old .Net frameworks (ASP.NET 1.1 or earlier) it was a pain to maintain the position of the scrollbar when doing a postback operation you have to write hell lot of javascript code. This was especially true when you had a grid on the page and went to edit a specific row.  Instead of staying on the desired row, the page would reload and you would be placed back at the top and have to scroll down.
In ASP.NET 2.0 and onwards you can simply add the MaintainScrollPostionOnPostBack attribute to the Page directive:
<%@ Page Language="C#" MaintainScrollPositionOnPostback="true" AutoEventWireup="true" CodeFile="abc.aspx.cs" Inherits="WebApplication1.abc" %>

Thursday 1 September 2011

Send mail in asp.net

  public static bool sendMail(string from, string subject, string to, string bcc, string body)
    {
        MailAddress mailAddress = new MailAddress(from);
        MailMessage mail = new MailMessage();
        mail.To.Add(to.ToString());
        mail.From = mailAddress;
        mail.Subject = subject;

        mail.Body = body;
        mail.IsBodyHtml = true;
        mail.Priority = MailPriority.High;
        SmtpClient smtp = new SmtpClient();
        bool flag = true;
        try
        {

            smtp.Host = smtp.gmail.com; //Or Your SMTP Server Address
            smtp.Credentials = new System.Net.NetworkCredential(your gmail id, ur gmail password);
//            smtp.Credentials = new System.Net.NetworkCredential(rrohit_0087@gmail.com,******);
            //Or your Smtp Email ID and Password
            smtp.EnableSsl = true;
            smtp.Send(mail);
        }
        catch
        {
            flag = false;
        }
        return flag;
    }

this is the method for sending the mail in this there are 5 parameter pass in this ..
in first enter the pass the gmail id by which you want to send mail
in second pass the subject of the mail
in third pass the id in which you want to send the mail .
in fourth pass the bcc id
in fourth pass the body of mail means what you want to send
---------------------------------------------------------------------------

Wednesday 17 August 2011

JIT Compiler

How many type of JIT in ASP >net

· Pre - JIT: - In Pre-JIT compilation, complete source code are converted into native code in a single cycle. This is done at the time of application deployment.
.
· Econo - JIT: - In Econo-JIT compilation, compiler compiles only those method which are called at run time. After execution of this method compiled method are removed from memory.
.
· Normal - JIT: - In Normal-JIT compilation, compiler compiles only those method which are called at run time. After executing this method, compiled method are stored in memory cache. Now further calling to compiled method will execute method from memory cached.


Thanks 
Rohit Srivastav

Tuesday 16 August 2011

Unconditional Love

Unconditional Love

A story is told about a soldier who was finally coming home after having fought in Vietnam. He called his parents from San Francisco.

"Mom and Dad, I'm coming home, but I've a favor to ask. I have a friend I'd like to bring home with me."

"Sure," they replied, "we'd love to meet him."

"There's something you should know the son continued, "he was hurt pretty badly in the fighting. He stepped on a land mind and lost an arm and a leg. He has nowhere else to go, and I want him to come live with us."

"I'm sorry to hear that, son. Maybe we can help him find somewhere to live."

"No, Mom and Dad, I want him to live with us."

"Son," said the father, "you don't know what you're asking. Someone with such a handicap would be a terrible burden on us. We have our own lives to live, and we can't let something like this interfere with our lives. I think you should just come home and forget about this guy. He'll find a way to live on his own."

At that point, the son hung up the phone. The parents heard nothing more from him. A few days later, however, they received a call from the San Francisco police. Their son had died after falling from a building, they were told. The police believed it was suicide. The grief-stricken parents flew to San Francisco and were taken to the city morgue to identify the body of their son. They recognized him, but to their horror they also discovered something they didn't know, their son had only one arm and one leg.

The parents in this story are like many of us. We find it easy to love those who are good-looking or fun to have around, but we don't like people who inconvenience us or make us feel uncomfortable. We would rather stay away from people who aren't as healthy, beautiful, or smart as we are. Thankfully, there's someone who won't treat us that way. Someone who loves us with an unconditional love that welcomes us into the forever family, regardless of how messed up we are.
i like this story so much
--------------------------
मुझे मुहब्बत के कायदे भी बताना नहीं आता
आखो में अश्को को छुपाना नहीं आता
खुद ही खुद को समझाना नहीं आता .
मुहब्बत का समन्दर भी तो इतना गहरा है
मै हर रोज़ कश्ती ले कर चला जाता हूँ
...मगर मुझे डूबना नहीं आता
मुझे मुहब्बत के कायदे भी बताना नहीं आता
खुद ही खुद को समझाना नहीं आता
---------------------------------------------------------
sweat story ....

Pencil - I am sorry.

Eraser - For what? you didn't do anything wrong.

Pencil - I am sorry because you get hurt because of me whenever i made a

mistake you are always there to erase it,

but as u make my mistakes vanish you lose a part of yourself, you get smaller and smaller . . .

Eraser - That's true but i don't mind you . . . see i was made to do this, i am

here to help you whenever you make a mistake and i know ''you will replace me

1 day, but i am happy because i hate to see you sad.''


kaas aisa hamse kisi ne aisa kaha hota
------------------------------------------------
Kahin wo mile to usay kehna!!!!
K Lot aao!!!!,

Lot aao k !!!
koi shiddat se,
Barri muddat se,
Barri muhabat se,
tumhara intizar kar raha hai,

Lot aao k....!!
kisi ki baatain,
Kisi ki yaadain,
kisi ki raatain
tum bin bohat adhuri hain....!!,

Lot aao k...!!
koi tum bin pal pal,
har pal,
har aaj ,
or har kal tanha hai,

Loat aao...!! k tum bin koi adhura hai................................!!

 --------------------------------------------------------------------------------
unhe nahi pata ki mai  unke saath kyon hu  
---------------------------------------------


BOHAT UDAAS HAI KOI TERE JAANE SE
HOSAKE TO LAUT AANA KISI BAHANE SE
TUU LAKH KHAFA SAHI MAGAR EIK BAAR TOO DEKH
KOI “TOOT” GAYA HAI TERE CHALE JANE SE

Thursday 11 August 2011

Post Back in ASP .Net

There are some definition of postback.
Post back is the process the sending data get back to server
for processing.
Is post back property checks whether page is being loaded for
first time.
if it is False :means first time loaded.
if it is True: means round trip to server.
=============
Postback: Postback is a event which fire when page data goes to server.
IsPostBack: Ispostback is page property of bool type and it become true when page come again to browser.
===
PostBack: Postback is the event which sends the form data
to the server. The server processes the data & sends it
back to the browser. The page goes through its full life
cycle & is rendered on the browser. It can be triggered by
using the server controls.And the IsPostBack property of
the page object may be used to check whether the page
request is a postback or not. IsPostBack property is of the
type Boolean.
=======
Today we are going to introduce you to the concept of PostBack in ASP.NET.

PostBack is the name given to the process of submitting an ASP.NET page to the server for processing . PostBack is done if certain credentials of the page are to be checked against a database (such as verification of username and password). This is something that a client machine is not able to accomplish and thus these details have to be ‘posted back’ to the server.

A simple example to illustrate the usage of PostBack is a login page. After the user has typed his username and password, he clicks on the ‘Login’ button. Upon the click, the page is sent to the server to check against the database/XML file to check if the user with supplied details is an authenticated user.

Then there arise certain events ( Listbox Index Changed,RadioButton Checked etc..) in an ASP.NET page upon which a PostBack might be needed. Consider the case in which you have 2 ComboBoxes. Let us say the first ComboBox asks you for the Country you reside in and the second one asks you for the State/Province in that country. Based upon the Country you select, the list of States/Provinces must be shown. Thus, in order to fill the values in the second ComboBox, the selection in the first ComboBox must be known to the server. Thus, as and when an item is selected in the first ComboBox, a PostBack must be done and the appropriate list of items must be filled in the second ComboBox.

To handle these situations, you need to enable the ‘Auto PostBack’ property for those controls whose events are going to trigger some kind of server processing (the case of the first ComboBox in the previous example).

Usage of IsPostBack in ASP.NWT-

IsPostBack is a Boolean property of a page when is set (=true) when a page is first loaded. Thus, the first time that the page loads the IsPostBack flag is false and for subsequent PostBacks, it is true. An important point to be noted here is that each time a PostBack occurs, the entire page including the Page_Load is ‘posted back‘ and executed.

Thus a very common programming practice is that whenever some part of the code is to be executed just the first time a page loads, it is checked against the IsPostBack flag.

If you have not understood the concept clearly, do not worry. Programming examples in subsequent posts will help making this concept clear.
=====
Page.IsPostBack is for forms that are runat=”server”. It is mostly used for same page validation, same page operations, … anything really same page!

It is also used to help keep bandwidth and rendering times down.

The main reason why people use IsPostBack is to stop taping the databases everytime a request is made. If you are on your default page and just do work via that page, you can use the if Not page.ispostback then statements to populate information. When pages are posted back to the sever and then rendered back to the client, they don’t have the need to repopulate the information since it was just populated. It is all kept in the viewstate and read back without using precious resources on the server.

It’s a very good and handy tool to know, and very easy to know as well! Any information that is not variable dependant should be only posted when the user first shows the page.

For another example, let’s say you are using menus that pull information from the database, articles that are previewed on a side bar for users with a link to the full article, and a search function that posts results that can be ordered by date, name, etc. Now, with the IsPostBack functionality, you can add the statement to all information that does not change when a request is made on the same page. You can add the “If Not Page.IsPostBack Then” for the menus and articles since the information does not change in anyway when a user clicked to have the search results ordered by name! This means that you do not have to tap the database three times, but only once! The information about the menus and articles are held in the viewstate so you don’t have to repopulate them.

Then for the “If Page.IsPostBack Then” statement, you can use for registration purposes for your site, post comments, etc. all by the Page.IsPostBack function. No code in the “If Page.IsPostBack Then” statement is fired when the page is requested by the client for the first time; And vice-versa, the “If Not Page.IsPostBack Then” function is only fired when the page is called for the first time, then uses viewstate to fill in the areas it is required to for every postback after that.

Hope this helps..

********************************************************************

Page.IsPostBack Is used to check if the user posted back to the page. Meaning they clicked a button or changed a field in the form that causes it to post back to itself.

Putting Not usually is used to check the initial load of the page.

You only need to fill databound fields on the initial load, so you put all your databinding code in the Not page.IsPostBack. The values are saved in the viewstate and can only be read by the form if it gets posted back to itself.

So, if it is a postback dont do databinding if its not a postback do databinding.


Welcome

this is the welcome page