Wednesday, 26 February 2014

How to find out day and year and month in respective date in sql server .2005 | sql server 2008.

How to find out day and year and month in respective date in sql server .2005 | sql server 2008.

we will see how can we find out day and month and year in given date separately .
to find out same we have to use DAY ,MONTH and YEAR keyword respectively which is by default or defined by sql server .
so no need to put some extra efforts.
just write same keyword after you use that keyword they will appear in pink colour in sql server.
lets look at examples.
suppose i have last date of submission my fee now i want to find  out day and month and year of lastdateofsubmission then i will
write like this.

for  day select DAY(LastSubmissionDate) from tableName
for month select MONTH(LastSubmissionDate) from tableName
for year  select Year(LastSubmissionDate) from tableName


now output will be
31 --day
2  --month
2014 --year


we can write in same line also..
select   DAY((LastSubmissionDate) ),MONTH ((LastSubmissionDate) ),YEAR ((LastSubmissionDate)  ) from tableNamewhere DueDate <> '' and DAY((LastSubmissionDate) ) in ('1','13','30')
which will gives you date which comes under day 1 , 13, 30 in every month and year.

Wednesday, 30 October 2013

How to find largest number in c | largest number examples.

How to find largest number in c | largest number examples.
Find largest number in c language without using  any loop with examples.


int maxnumber(int num1, int num2, int num3)
{
    int largestnumber;
        largestnumber=int num1; /*  Assume number 1 is largest number*/
        if (num2 > largestumber)
        {
            largetnumber=num2;   /* number 2 is largest number*/

        }
if (num3 > largestnumber)
{
largestnumber=num3;

}

return largestnumber;
}


we can do this by using for loop but here i have shown how to find out largest number using

if statement.

Tuesday, 29 October 2013

Difference between Delete |Truncate | Drop in Sql server

Difference between Delete |Truncate | Drop  in Sql server

in this article i am goig to show you what is difference between delete and truncate and
drop command.


1->Delete

Delete command mostly use for delete single row or multiple row or delete all the row in

table.

take an examples ..
delete stud .
Will delete all rows in stud table.
now ,
delete from stud where condition..
will delete single or multiple record.
it is faster slower than truncate.
we can rollback .



2->Truncate.
Will delete all the data from table .
we can not specify where condition.
Faster than delete .
we can't rollback until we use transaction.
truncate table tablename


3-> drop

to delete the table also with data.
drop table tablename.
rollback but in transaction.


remember one thing once we committed we wont undo record or table in delete or truncate or

drop command.


begin tran

delete  fee
rollback tran

begin tran
delete from stud where id=104

drop table stud

delete will keep your identity as well.
second time entry will tale last id number where as in truncate that will start from 1.

Wednesday, 23 October 2013

How to upload multiple file in c# | asp.net | Created directory of file name

How to upload multiple file in c# | asp.net | Created directory of file name
How to upload multiple file in asp.net with directory creation.
In this article we are going to learn how to upload multiple files in asp.net with c# code.
We can also find out if file has already uploaded then there will be directory creation with existing file name.
Lets take a examples ..
If i want to upload my resume file and there is three resume so what i need to do is , first of all i will select my resume 1

then 2 and last 3..
while uploading 3 files the resume1.doc , resume2.doc , resume3.doc will be selected at same time same names directory will

be created ..
but if you have already added or uploaded any of resume out of this then it will inform you that file already exists.

import using System.IO; namespace.

.aspx page



  <tr><td><asp:FileUpload runat="server" ID="fp1" /></td></tr>
  <tr><td><asp:FileUpload runat="server" ID="fp2" /></td></tr>
  <tr><td><asp:FileUpload runat="server" ID="fp3" /></td></tr>



now code to .cs page.


  private void Fileupload()
        {
            if (fp1.HasFile)
                {
                   
                   
                    string filename = fp1.FileName;
                  string str=  FunchekFilealreadythere(filename);
                  String filePath = Server.MapPath(@"~/upload_resume/"+str+"/"+ fp1.FileName);
                 fp1.SaveAs(filePath);//will add file name in file name directory.
            }

                if (fp2.HasFile)
                {
                 string filename1 = fp2.FileName;
                 string str1 = FunchekFilealreadythere(filename1);
                 String filePath1 = Server.MapPath(@"~/upload_resume/" + str1 + "/" + fp2.FileName);
                 fp2.SaveAs(filePath1);

                }


                if (fp3.HasFile)
                {
                    string filename2 = fp3.FileName;
                    string str2 = FunchekFilealreadythere(filename2);
                    String filePath2 = Server.MapPath(@"~/upload_resume/" + str2 + "/" + fp3.FileName);
                    fp3.SaveAs(filePath2);

                }


           
            else
            {
                Response.Write("uploaded");
            }
        }

        public string    FunchekFilealreadythereg filename)
        {
            string nm=filename ;
            string[] fnm=new string [1];
            fnm=nm .Split ('.');//will just take file name not extension.


            if (!System.IO.Directory.Exists(Server.MapPath(@"~/upload_resume/" + fnm[0] + "")))
            {
                System.IO.Directory.CreateDirectory(Server.MapPath(@"~/upload_resume/" + fnm [0]+ ""));
            }
            return fnm[0];
           
        }

here i have shown how to upload three files and create directory as well .
You can upload multiple files and create directory  how much you need.

System.Web.HttpException: 'HtmlSelect' cannot have children of type 'LiteralControl'.

System.Web.HttpException: 'HtmlSelect' cannot have children of type 'LiteralControl'.
System.Web.HttpException: 'HtmlSelect' cannot have children of type 'LiteralControl'.

if you are getting this type of error while executing on running your asp.net application

in c# or in vb.net you must know about real cause or from where this error is occurring.

lets.. reavel this now what i did i just took

<select>
<option>
some information
</option>

</select>

and added runat="server" at .aspx page .


<select size="1" name="region" id="region"  runat="server">

now if we  run its gives error System.Web.HttpException: 'HtmlSelect' cannot have children

of type 'LiteralControl'....
to remove this error and make your application work easily..just add form name in your

.aspx pahe and add then add this line of code to .cs page.

remove runat="server"
Request.Form["region"].ToString();
and try now hope its works..