Saturday, 22 December 2012

Difference between Hidden Field and Viewstate in asp.net. | Vb.Net

Difference between Hidden Field and Viewstate in asp.net. | Vb.Net

In asp.net hidden field and Viewstate both manage memory management.
we can store value in hidden field and viewstate also.
now lets check the difference between both

1->Hidden Field is server control and Viewstate is variable .
2->Hidden field won't visible in browser same for Viewstate but if we will use hidden field ,
 we will get more extra encrypted code in view source whereas if we will use Viewstate we will not get that much of extra code.
3-><input type="hidden" id="hdn" runat="server">
To assign value  to hidden field .. use value property of hidden field
 hdn.Value="sometext" // assingning value  to hidden field
lablet.text=hdn.value   // storing value of hidden field into variable

For viewstate
Viewstate("storeval")="sometext" // assigning value into viewstate
string str=Viewstate("storeval")   //storing value of viewstate into variable
in c# syntax is different.

so in these way we can use hidden field and view state.
hidden field go to the server but Viewstate maintain  after postback whithout touching server.

I don't know whether we can store Datatable value in hidden field but its possible in Viewstate.


Sunday, 16 December 2012

Alert in asp.net on code behind page with vb.net

Alert in asp.net on code behind page with vb.net

 Protected Sub btnEnter_Click( ) Handles btnSubmit.Click

      Dim str As String
    str = "select field1 , field2 from table_name where field1=" & Trim(txtval.Text) & " and field2='somevalue' and tdate='"

& txtdate.SelectedDate & "'"
            Dim datareader_rad As SqlClient.SqlDataReader
            Dim sqlcommandname As New SqlCommand(str, con)
            con.Open()

           datareader_rad= sqlcommandname.ExecuteReader

            If datareader_rad .Read Then
                Try
     Response.Write("<script language='javascript'>alert('already value is  there in list.');</script>")
                Catch ex As Exception
                Finally

                    con.Close()

                End Try
            Else
                con.Close()
                dr.Close()

                Try
                    cmd = New SqlCommand("stoted_procedure_name", con)
                    cmd.CommandType = CommandType.StoredProcedure
                    cmd.Parameters.AddWithValue("@field1", Trim(txt1.Text))
                    cmd.Parameters.AddWithValue("@tablefield2", Trim(txt2.Text))
                    cmd.Parameters.AddWithValue("@time", Trim(txttime.Text))
                       Catch ex As Exception
                End Try
            End If
        End Sub
What  i did here just took one datareader and stored value ,  means stored field all value into datareader then checked using datareader_rad .read it shows if value already present in datareader then will show alert box that "already value is  entered".

     Response.Write("<script language='javascript'>alert('already value is  entered.');</script>")
by this code we can learn about javascript in  code behind  page in asp.net using vb.net



c program | Sorting of given number | implementation of Insertion sort

c program | Sorting of given number  |  implementation of Insertion sort

Logic and examples to sort given number in list.
In this article we will get idea about to sort number .
user will enter the number in any order like 4,5,3,67,8, etc..
and when we include in program it will get output like 3,4,5,8,67.
before to sort given number all the entered number will save in list .
then after it will sort by ascending order like small to bigger number and will show in ordered .
this program we call as Program for implementation of Insertion sort also.

#include<stdio.h>// header file
#include<conio.h>
#define max 20

void main() // start of main
{
int i,j,n,k,t,temp,a[max];//intializing variable and temp memory
clrscr();
printf("\How many no. you want to insert into list:- ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter %d no:- ",i+1);
scanf("%d",&a[i]);
}
printf("\nUnsorted list is:-\n");// will display unsorted list
for(i=0;i<n;i++)
printf("\n%d",a[i]);
for(i=1;i<n;i++)
{
for(j=0;j<i;j++)
{
if(a[i]<a[j])// cheking first value is less than next one
{
temp=a[j];
a[j]=a[i];
for(k=i;k>j;k--)
a[k]=a[k-1];
a[k+1]=temp;
}
}
}
printf("\n\nSorted list is:-\n");// will print sorted order in a list
for(i=0;i<n;i++)
printf("\n%d",a[i]);
getch();
}


Saturday, 15 December 2012

Fibonacci series in c program | Mathematical functions code with execution and comments

Fibonacci series  in c program |  Mathematical functions code with execution and comments

How to print first n terms of Fibonacci series in c language
series of addition of last two number is third number.
0,1,2,3,5.........so on
0+1=1
1+2=3
2+3=5.
we can find out fibbonacci series at given number just we have to enter that number.
in this article we will see how to write series program in c language.

/*Program to print first n terms of Fibonacci series*/
#include<stdio.h> // including header files.
#include<conio.h>
void main() // start of main
{
int a,b,c,n,i; // initializing variables
clrscr();

//Accept no. of terms
printf("Enter no. of terms u want in the series: \n");
scanf("%d",&n);
a=1;  // first we initialized a=1 and b as 0. so we can start to in  the series.
b=0;

//print fibbonacci series
for(i=n;i!=0;i--)  //supose n=25 then  check i not equal 0 and decrement of i
{
c=a+b; //c=0+1=1
a=b;    // now now a=2
b=c;   //now b=1
ptint c=1
next execution
c=a+b; //c=0+1=1
a=b;    // now now a=0
b=c;   //now b=1

print 0,1

next execution
c=a+b; //c=2+2=1
a=b;    // now now a=2
b=c;   //now b=2

print 2  so on..


Like this it will print
0,1,2,3,5,8,13,21


printf("%d ",c);
}

getch();
}

Armstrong number example in c program with coments

Armstrong number example in c program with coments

Armstrong number in c program with source code | comments | execution line by line


In this article i have shown how to Write program for Armstrong number in c  using function with while loop.
Basically we can write simple program for Armstrong number but by using function if we are

writing then its  scope will be different.
first of all get all the idea about what is Armstrong number .
its definition then only one programmer can develop his logic.
Armstrong number is number which is equal to sum its individual number cube.
cube means multiplication of same number thrice or three times.
suppose i want to check number 153 is Armstrong or not, then answer is yes .
because , 153=(1*1*1) + (5*5*5) + (3*3*3) =1+125 + 27 =126 + 27=153.
in this line 1 and 5 and 3 are 153 's individual number .and sum of cube of all three

numbers that number.
so , i think you got the little idea about Armstrong number.
so here we are going to write Armstrong number program in c language.

#include<stdio.h>  // including header files
#include<conio.h>
 void armstrong(int n);   // calling function armstrong(int n)
void main()
{
int n;   //initializing variable n
clrscr();
printf("enter the number");
scanf("%d",&n);   //153
arm(n);    // now n=153
getch();
}
void arm (int n)
{
int r,sum=0,no;
no=n;   //no=153
while(n>0)
{
r=n%10;   //taking mod  (153%10)=15 and r=3 and n=15
sum=(r*r*r)+sum; //3*3*3 + sum=27+0=27 so sum=27
n=n/10;   // now n=15

    // after first execution


r=n%10;   //taking mod  (15%10)=1 and mod =5 and n=10
sum=(r*r*r)+sum; //5*5*5 + sum=125+27=152
n=n/10;   // now n=10

     // after second execution

r=n%10;   //taking mod  (10%10)=0 and mod =1 and n=0
sum=(r*r*r)+sum; //1*1*1 + sum=152+1=153
n=n/10;     // after last execution
}
 
if(no==sum)        // now sum=153 and no=153 both are same hence 153 is armstrong number
printf("given number is armstrrong");
else
printf("not armstrong");

}


Armstrong number program is very simple program just we  should know about c logic and loop

syntax and concept about program.