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.



Tuesday, 8 January 2013

Image upload code in c# | asp.net image file uploading in database | gridview


How to upload images in asp.net using c#

string path = Server.MapPath("Images/"); //Images is folder here it will show full path where file or pic is going to store//

lblMessage.Text = path;

if (FileUpload1.HasFile)

{

string Filext = Path.GetExtension(FileUpload1.FileName);

if(Filext==".jpg" || Filext==".png")

{
 HttpPostedFile myFile = FileUpload1.PostedFile;
                int nFileLen = (myFile.ContentLength)/1000; // will check file length
FileUpload1.SaveAs(path+ FileUpload1.FileName);
string filnm="~/Images/"+FileUpload1.FileName;
string nm = txtName.Text.Trim();
string filenm = filnm.ToString();
string query="insert into images (ImageName,Image)values (@imgnm,@imgpath)";
SqlCommand cmd=new SqlCommand(query,con);
cmd.Parameters.AddWithValue("@imgnm", nm);
cmd.Parameters.AddWithValue("@imgpath", filenm);
SqlCommand disply = new SqlCommand("select * from images", con);
SqlDataAdapter da = new SqlDataAdapter(disply);
DataTable dt = new DataTable();
da.Fill(dt);
grdvw.DataSource = dt;
grdvw.DataBind();
con.Open();
int i = 0;
i= cmd.ExecuteNonQuery();
if(i>0)
{
lblMessage.Text="Image uploaded succesfully";
}
else
{
lblMessage.Text="Please select the image";
}
}
else
{
lblMessage.Text="please selest .png or .jpg files only";
} } }



<asp:fileupload id="FileUpload1" runat="server">
<asp:button id="btnupload1" onclick="btnupload1_Click" runat="server" text="Upload">

<asp:textbox id="txtName" runat="server" width="95px">

</asp:textbox>
<asp:label id="lblMessage" runat="server"></asp:label>
<asp:gridview autogeneratecolumns="false" id="grdvw" runat="server">
<columns>
<asp:boundfield datafield="ID" headertext="Number">
<asp:boundfield datafield="ImageName" headertext="Product">
<asp:imagefield controlstyle-height="120px" controlstyle-width="120px" dataimageurlfield="Image" headertext="Image">
</asp:imagefield>
</asp:boundfield></asp:boundfield></columns>
</asp:gridview></asp:button></asp:fileupload></div>

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();
}