Tuesday, 12 March 2013

Sum Of series in c#.net source code with output and explanation

Sum Of series in c#.net source code with output and explanation

Sum Of series in c#.net source code with output and explanation
in this program we will see how to calculate sum of series till sum number like 10 , 20 , etc....
Now what we will do we will just take two value assign them as 0  and 1. so , at least we will get
some value at start.
In this article i have shown here how  to calculate sum of series in c# .net on Page Init
 event.


 protected void Page_Init(object sender, EventArgs e)
    {
       
     
       int a=0;   //here i have initialize two valus as 0 and 1.
        int b=1;
        int num=20;
        Response.Write("Sum Of series Before:"+num);
        Response.Write("</br>");
       int  sum=0;
        for (int j=1;j<=num;j++)
        {
            sum=a+b; //swappping.............
            a=b;
            b=sum;
            Response.Write(sum+"-");  // printing the values.......
        }

       
        }


OUTPUT
Sum Of series Before:20
1-2-3-5-8-13-21-34-55-89-144-233-377-610-987-1597-2584-4181-6765-10946  

IF YOU WILL TAKE NUM=10
THEN OUTPUT WILL

Sum Of series Before:10
1-2-3-5-8-13-21-34-55-89 

Monday, 11 March 2013

Factorial Number program source code | From 1 to n range | c#.net

  Factorial Number program source code | From 1 to n range | c#.net
  Factorial Number program source code | From 1 to n range | c#.net
In this program i have shown how to find factorial number of given range.
using for loop i have calculated factorial number from 1  to 5 .
But , we  can calculate factorial number from 1 to n using below given source code.
output is there.
same logic we  can apply in c language , vb.net also but difference is only of syntax will be changed.
rest logic will be same.

 protected void Page_Init(object sender, EventArgs e)
    {

        int sum = 1;
        int i = 5;

        for (int j = i; j > 0; )
        {

            for (int k = 1; k <= j; )
            {

                sum = sum * j;
                j--;
            }
            Response.Write("Factorial of " + i + "is" + "\t" + sum);
            Response.Write("</br>");
            i--;
            j = i;
            sum = 1;

        }
  
          
               }


Factorial of 5 is 120
Factorial of 4 is 24
Factorial of 3 is 6
Factorial of 2 is 2
Factorial of 1 is 1

Prime Number source code | C#.Net | Prime Number from 1 to n..with examples and comments

Prime Number source code | C#.Net | Prime Number from 1 to n..with examples and comments

 source code how to calculate prime number in c#.net.With valid and correct output.
Definition Of Prime Number:- The number which is divisible by 1 and itself.
or we can say prime number is a number which has only two factor first one is 1 and second
is that number itself.
 in this article i have shown to calculate prime number from one range to n range and also how to find
simple number  is prime or not.


Now first to calculate whether entered number is prime number or not.
here is code:- on page init


   
    protected void Page_init(object sender, EventArgs e)
    {
           
        int num=20, flag=0;
     
     
        for (int i=2;i<;num/2++)//i will be less than half of number it will also work.
        {
          if(num%i==0)
          {
          flag=1;   // now entered number 20 is divisible by 2 means 20 has another factor that is 2
so , it  is not prime number no need to go in execution use break statement.
          break;
         
          }
          else
          {
          flag=0;
          }
        }
        if (flag==0)
        {
          Response.Write(" +num+"is  not prime number :-");
        Response.Write("</br>");
        }
else
{

 Response.Write( +num+"is  a  prime number :-");
}

       
     


    }
}


It was simple program to check number is prime or not now i want to check number from n to n+...
or 1 to 20 , 1 to 100 , 1 to 1000 just enter num=100 or num=1000 as you want range.

   
    protected void Page_init(object sender, EventArgs e)
    {
           
        int num=20, flag=0;
        Response.Write("Prime Number from 2 to" +num+"is :-");
        Response.Write("</br>");
        for (int j=2;j<num;j++)
        {
        for (int i=2;i<j;i++)
        {
          if(j%i==0)
          {
          flag=1;
          break;
         
          }
          else
          {
          flag=0;
          }
        }
        if (flag==0)
        {
        Response.Write(j);
         Response.Write("</br>");
        }
       
        }


    }
}


Prime Number from 2 to 20 is :-
2
3
5
7
11
13
17
19



Wednesday, 6 March 2013

How to store date value into viewstate in vb.net | c#.net.

How to store date value into viewstate in vb.net | c#.net.

How to store date value into viewstate in vb.net | c#.net with explanation and example in asp.net.
How to check whether viewstate is null or have some values.

It is very simple to store value and retrieve it on another place.
we can store datatable , simple variable in viewstate to fetch same data later
 on whenever we need to use that respective data.
so coming on point i am goinG to write code how to store date value or data time into viewstate and display it.

            ViewState("fromdate") = controlName1.SelectedDate
            ViewState("Todate") = controlName2.SelectedDate

NOW Here i am assigning data value into viewstate named  fromdate and todate.

in c#

    ViewState["fromdate"]= controlName1.SelectedDate
    ViewState["Todate"]= controlName2.SelectedDate

now i have store from date value and to date value into viewstate named as
fromdate and todate both are in doublw quotes.now i want to retrieve that same value into another function.
what i will do , i will just take control name and  assign viewstate value there.

 Dim lbl As New Label
 lbl.Text = CType(ViewState("frm"), Date)

so , label will display data value.


now in c# 
  lbl = New Label()
 lbl.Text = CType(ViewState["frm"], Date);


just change that bracket style.

so if you want to use same variable after postback use viewstate .
less burdon on server, because viewstate is client side state management.once page unloaded viewstate destroy.


after if you want to check whether viewstate  has value or not you can write code like this

  Dim lbl As New Label
            If ViewState("frm") = CType("12:00:00 AM", Date) Then
                lbl.Text = "something"
            Else
                lbl.Text = CType(ViewState("frm"), Date)
                Response.Write(lbl.Text)
            End If

Try it and implement it.



Tuesday, 5 February 2013

Crystal Report viewer not showing(displaying) in toolbox visual studio 2005|2008.


How to add crystal Report viewer   in toolbox
when you are trying to add crystal report viewer in your .aspx form and if you are not getting
that module in toolbox simply do one thing.
Just right click on toolbox >add new tab -> write Reporting or whtever name you want to give your module.

step 1->right click on toolbox  new box will appear blank just give name to box.optin will appear add tab.
give any defalt tab name.



step2->right click on add given  tab name.and select choose item which you want to import.






NOW BOX WILL OPEN TO GIVE YOU MORE REFERENCES SO YOU CAN CHOOSE AS PER YOUR REQUIREMENT.
now here you will get reference of crystal report viewer to add in your toolbox.select all the reference which belongs or useful in designing of crystal report.
Now After all step just go  to your toolbox left side and check by clicking + sign .whatever name you had specified to crystal report tab.
now you can open your .aspx  page and drag report viewer from report tab  from toolbox.