Predefined Functions in SqlServer

Hi friends
               here are the predefined function in SQL Server 2005 which helps you in your programming .

Mathematical Functions
Abs,Ceiling,Floor,Exp,round

Select abs(-55) -- output will be 55 Get absolute value
Select ceiling(55.3) -- output '56' get round the value
Select Floor(45.8) -- output '45' get round the value
Select Exp(0) -- get a exponential value of '0' that is 1
Select Round(225.245874,3) -- output 225.246000 round a value after the no.of digit.

Trignometric Functions
Sin,Cos,Tan,Log

Select Sin(0) -- get sin value of '0' that is 0
Select Cos(0) -- get cos value of '0' that is 1
Select Tan(0) -- get tan value of '0' that is 0

String Functions
Ascii,Char,Reverse,SubString,
Stuff,Replicate,Replace,Ltrim,Rtrim

Select Ascii('A') -- Output '65' get Ascii value of 'A'
Select Char(97) -- output 'a' get char value of 97
Select Reverse('REVERSE')-- output 'ESREVER' get the reverse value of string
Select Substring('Hello World',3,5) -- output 'llo w'
Select Stuff('world',2,5,'welcome') -- output 'wwelcomorlde' Here 2 --> Start Position 5 --> Replace Char Length
Select Replicate('hello ',3) -- output 'hello hello hello ' its repeat a Value 3 times Here 3 --> No.of Times
Select Replace('abcdefgh','de','xy')-- output 'abcxyfgh'
Select Ltrim(' hello ') -- output 'hello ' remove a space in front of the string
Select Rtrim(' hello ') -- output ' hello' remove a space in end of the string

Date Functions
GetDate,DateAdd,DateDiff,DatePart

Select GetDate()--Get Current Date
Select Dateadd(dd,2,getdate())--Add 2 days from Current Date
Select Datediff(dd,'1985-05-06','2005-06-09') --Get Date difference between those days
Select Datepart(dd,getdate()) --get a date only from currentdate

System Functions
Db_Id,Db_Name,IsDate,Isnumeric

Select db_id('master')-- Get order of that Database
Select db_name(4)--Get a 4th order of name in a database
Select isdate('02/31/2005') --Date is availabe or not Here output comes '0' or '1'
Select isnumeric(15s) --Value is numeric or not Here output comes '0' or '1'

Aggregate Functions
Count,Max,Min,Avg,Sum

Count() --> Get Total Count of Row
Max() --> Get a Maximum value of a Column
Min() --> Get a Minimum value of a Column
Avg() --> Get a Average value of a column
Sum() --> Get Total Value of a Column 

Hope this will helps you
 Regards
Rajesh 

0 comments:

Controlling Authorization permissions in Asp.Net Application in C#

hi Friend 
    i am here with article on Form Authentication and Authorization in Web config file .When we use the forms based Authentication in Asp.Net Application. Only the authenticated users can access pages in the application. Unauthenticated users are redirected to the specified login page provided by the loginURL tag. If the user login from that page then the user is redirected to page they wanted to go.

We use the location tag to define the rules in the Web.Config.
<configuration>
        <system.web>
               <authentication mode="Forms" >
                       <forms loginUrl="login.aspx" name=".aspFormAuth" 
protection="None" path="/" timeout="30" >
                       </forms>
               </authentication>
<!—We first deny any unauthorized user in the site. -->
               <authorization>
                       <deny users="?" /> 
               </authorization>
        </system.web>
<!—Now we allow all the user to Home.aspx page here any unauthenticated User can 
access this page   -->
               <location path="Home.aspx">
               <system.web>
               <authorization>
                       <allow users ="*" />
               </authorization>
               </system.web>
               </location>
<!—we can also give unauthenticated users permission on a given directory.  -->
               <location path="FolderName">
               <system.web>
               <authorization>
                       <allow users ="*" />
               </authorization>
               </system.web>
               </location>
</configuration>
 
-------------------------------------Code Behind-----------------------------------
 
here is the code behing that you can use Code behind on any event to set authentication  
 
 if (FormsAuthentication.Authenticate(txtUserName.Value, txtPassword.Value))
       {
          FormsAuthentication.RedirectFromLoginPage(txtUserName.Value, false);
       }
       else
       {
          lblMessage.Text ="Unauthenticate User";

          FormsAuthentication.SignOut();
      }
 
 
 Hope this artical help you in your application
 
Regards 
 Rajesh 

0 comments:

Customizing SectionGroups and Sections in Web.config in C#


Hi Friends,
 some time  we need to declare our own SectionGroups and Sections in web.config depending upon certain situations.  here i am explaining you how to access and use the Section values in your application.
Here, I have created two Sections under one SectionGroup.
Hope this article will help whenever you want to handle SectionGroups in your web.config.


<configuration>
<configSections>
 <sectionGroup name="SectionGroupName"> //Here we declare the name of the section group
   <section name="SectionName1" 
     type=="System.Configuration.NameValueSectionHandler,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowLocation="true" allowDefinition="Everywhere"/>//Section name 1
   <section name="Sectionname2" 
     type=="System.Configuration.NameValueSectionHandler,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowLocation="true" allowDefinition="Everywhere"/>//Section name 2
</sectionGroup>
</configSections>


------------------------Here is the Syntax of Section Group--------------------------------

<sectionGroup 
   name="section name"
   type="configuration section handler class, assembly file name, version, culture, public key token">
   <section />
/>

The following sections describe attributes
Attribute
Description
Name
Required String attribute.
Specifies the name of the configuration section or element that is associated with the configuration section handler that is specified by the typeattribute. This is the name of the group element as it appears in the section settings area


type
Required String attribute.
Specifies the name of the configuration section handler class that handles the processing of the configuration settings that are in the section or element that is specified in the name attribute. Use the following format:
type=" Fully qualified class name , assembly file name, version, culture, public key token"
The definition must match the assembly reference. For example, if the version number in the following code example does not match the assembly, an error occurs.
type="MyConfigSectionHandler.MyHandler,MyCustomConfigurationHandler,Version=1.0.0.0,Culture




---------------Assign the Value of Sections-----------------------
<configuration>

<SectionGroupName>
<SectionName1>
<add key="A1" value="AWCompany"/>
<add key="A2" value="AXCompany"/>
</SectionName1>
<SectionName2>
<add key="S1" value="AWCompany"/>
<add key="S2" value="AXCompany"/>
</SectionName2>
</SectionGroupName>
</configuration>


----------------Access the value on page------------------------


                System.Collections.Specialized.NameValueCollection collectionObj=
                  (System.Collections.Specialized.NameValueCollection)
                  System.Configuration.ConfigurationSettings.GetConfig("SectionGroupName/SectionName1"); 
                collectionObj.Get(0).ToString();//Here Get(0) is first index value of section
              




Hope this article will help you...


Regards 
Rajesh


0 comments:

New Dynamic Sites Launched in jaipur Must See this!!!!



www.pinkcityroyals.com
India's No. one online B2B Advertisement Portal on Jaipur, Complete Jaipur Business Directory

www.jaipurtourandtravels.com
Jaipur Tour and Travels Portal, Jaipur Tour and Travels, Jaipur Tour packages, Jaipur Travels, JAIPUR
Travel Guide, Jaipur tour operators, Rajasthan Tour India Tour Package

www.dreamssofttechnology.com
Jaipur Software Development, Jaipur Web Development, jaipur Web Hosting, Jaipur Domain Reg. , Jaipur Web graphics Design, Complete Online Internet marketing Solutions Jaipur.

Jaipur’s Best Academic Training Providers, Best Content with Best Experts, (Associated with Guwadiya Softwares and Trainings).

2 comments:

How to use .mdf database in our Application using C#

  Hi Friend,

    we can use .mfd as a database in our application by using connectionstring in web config having a details of .mdf database .like this.

 <add name="ConnectionString" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|ASPNETDB.MDF;User Instance=true" providerName="System.Data.SqlClient"/>

If you want to get the login User Details through Membership table in .mdf file you can use this code:



using System.Web.Security;

 MembershipUser objUserID = Membership.GetUser();
string sUserID = objUserID.ProviderUserKey.ToString();

this will give you the Datails of login User ..

Thanks & Regards

Rajesh

0 comments:

Programmatically determine Total Free Space available on your Hard Drive

using System.IO;

public partial class DescSpace : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int i = 0;
        foreach (DriveInfo drive in DriveInfo.GetDrives())
        {
            try
            {
                Label lblDriveName = new Label();
                Label lblDriveSize = new Label();
                lblDriveName.ID = "lblDriveName" + i.ToString();
                lblDriveSize.ID = "lblDriveSize"+i.ToString();
                lblDriveName.Text = "Drive Name is :" + drive.RootDirectory.ToString();
                lblDriveSize.Text="Drive Having Size in MB :"+Convert.ToString((drive.AvailableFreeSpace / 1024) / 1024);
                PlaceHolder1.Controls.Add(lblDriveName);
                PlaceHolder1.Controls.Add(lblDriveSize);
                i = i + 1;
            }
            catch (IOException io)
            {
                
            }
            catch (Exception ex)
            {
              
            }
        }
       
    }

0 comments:

Fatching Data From Excel Sheet to Dataset in C#


Hi Friends

Here are the few steps for fetching  data from excel sheet into a DataSet in C# . you simply flow the steps and get the Data into dataset.

Step 1 :- In first step we have to  save that Excel file into App_Data folder .we need to write the code like this,

if (uploadExel.HasFile)
{
string sName = Excel.FileName;
// get the extension of the excel sheep
string ext = System.IO.Path.GetExtension(sName);
if (ext == ".xls")
{
uploadExel.SaveAs(Server.MapPath("../App_Data/" + "Books" + ext)); //Here we save the file into App_Data
}
}

Step 2 :-Now we have to create a DataSet which is use to  hold values from Excelsheet.

DataSet dsExcel = new DataSet();


Step 3
:- Now connect with excel sheet using OLEDB data adapter to fatch all the records

OleDbConnection connection = new OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=|DataDirectory|Books.xls;Extended Properties=Excel 8.0");
public DataSet getExcelData()
{

OleDbDataAdapter da = new OleDbDataAdapter("select * from [ExcelFileName$]", connection);
DataSet dsExcel  = new DataSet();
try
{
da.Fill(dsExcel , " ExcelFileName ");
}
catch (Exception ex)
{
 dsExcel  = null;
}
finally
{
con.Close();
}
return dsExcel ;

}

Step 4
: - Now call the above method and assign it to dataset and put a loop to get the values

if (dsExcel  == null)
{
lblMsg.Text = "No Data us Return or file Name is not Present. ";
return;
}
else
{
int count = dsExcel .Tables[0].Rows.Count;
for (int i = 0; i < count; i++)
{
// Here We can Get the Data from Excel Sheet..
}
}

}

}
Hope this will help you 
Regards,
Rajesh



0 comments: