Thursday, September 29, 2011

Found Date is Valied or Not


protected void btnCheck_Click(object sender, EventArgs e)
    {
        string s= IsDate(TextBox1.Text);
        Response.Write(s);
    }
    private string IsDate(string strDate)
    {
        DateTime dt;
        string boolIsDate = "ok it is date format";
        try
        {
            dt = DateTime.Parse(strDate);
        }
        catch
        {
            boolIsDate = "no date format";
        }
        return boolIsDate;
    }

MySQL Database Back Up and Restore From Front end


protected void btnBackup_Click(object sender, EventArgs e)
    {
        DatabaseBackup("C:\\Program Files\\MySQL\\MySQL Server 5.0\\bin\\mysqldump.exe");

        
    }
    public void DatabaseBackup(string ExeLocation)
    {
        string tmestr = "";
        tmestr = "hostels_db" + "-" + DateTime.Now.ToShortDateString() + ".sql";
        tmestr = tmestr.Replace("/", "-");
        tmestr = "E:/" + tmestr;
        StreamWriter file = new StreamWriter(tmestr);
        ProcessStartInfo proc = new ProcessStartInfo();
        string cmd = string.Format(@"-u{0} -p{1} -h{2} {3} --routines", "root", "root", "localhost", "hostels_db");
        ExeLocation = ExeLocation.Replace("\\", @"\");
        proc.FileName = ExeLocation;
        proc.RedirectStandardInput = false;
        proc.RedirectStandardOutput = true;
        proc.Arguments = cmd;
        proc.UseShellExecute = false;
        Process p = Process.Start(proc);
        string res;
        res = p.StandardOutput.ReadToEnd();
        #region
        //if (tmestr.Contains("*/;;"))
        //{
        //    tmestr.Replace("*/;;", "");
        //}
        //if (tmestr.Contains("/*!50003"))
        //{
        //    tmestr.Replace("/*!50003", "");
        //}
        //if (tmestr.Contains("*/ /*!50020"))
        //{
        //    tmestr.Replace("*/ /*!50020", "");
        //}
        #endregion
        file.WriteLine(res);
        p.WaitForExit();
        file.Close();
        Response.Write("Backup Completed...");

    }    
    protected void btnRestore_Click(object sender, EventArgs e)
    {
        DataBaseRestore("C:\\Program Files\\MySQL\\MySQL Server 5.0\\bin\\mysqldump.exe");
        //MySqlDataAdapter da = new MySqlDataAdapter("restore database from disk ",cn);
       
    }
    public void DataBaseRestore(string path)
    {
        string path1 = "E:\\hostels_db 952011.sql";
        path1 = path1.Replace("\\", @"\");
        StreamReader file = new StreamReader(path1);
        string input = file.ReadToEnd();
        file.Close();

        ProcessStartInfo psi = new ProcessStartInfo();
        psi.FileName = path;

        psi.RedirectStandardInput = true;
        psi.RedirectStandardOutput = false;
        psi.Arguments = string.Format(@"-u{0} -p{1} -h{2} {3}", "root", "root", "localhost", "hostels_db");
        psi.UseShellExecute = false;


        Process process = Process.Start(psi);
        process.StandardInput.WriteLine(input);
        process.StandardInput.Close();
        process.WaitForExit();
        process.Close();
        Response.Write("Backup Restore Completed...");
    }

Wednesday, September 28, 2011

How to count number of columns in a table in sql server2005


SQL Query--1:

select count(*) from information_Schema.columns where table_name='tblNew'

SQL Query--2:

select count(*) from syscolumns where id in (select id from sysobjects where sysobjects.name = 'tblNew')

Monday, September 26, 2011

What is difference between HTTP Handler and HTTP Module.


Http Handlers:
Http handlers are component developed by asp.net developers to work as end point to asp.net pipeline. It has to implement System.Web.IHttpHandler interface and this will act as target for asp.net requests. Handlers can be act as ISAPI dlls the only difference between ISAPI dlls and HTTP Handlers are Handlers can be called directly URL as compare to ISAPI Dlls.
Http Modules:
Http modules are objects which also participate in the asp.net request pipeline but it does job after and before HTTP Handlers complete its work. For example it will associate a session and cache with asp.net request. It implements System.Web.IHttpModule interface.

Monday, September 19, 2011

GridView Paging,Sorting,Salary Total Display in Footer Row With Out Bound Fields



Source Code

<table class="style1">
        <tr>
            <td align="center">
                <asp:GridView ID="GridView1" runat="server"
                    BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px"
                    CellPadding="2" ForeColor="Black" GridLines="None"
                    onrowdatabound="GridView1_RowDataBound" ShowFooter="True"
                    AllowPaging="True" onpageindexchanging="GridView1_PageIndexChanging"
                    PageSize="4" AllowSorting="True" onsorting="GridView1_Sorting"
                    AutoGenerateColumns="false">
                    <FooterStyle BackColor="Tan" />
                    <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
                        HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
                    <HeaderStyle BackColor="Tan" Font-Bold="True" />
                    <AlternatingRowStyle BackColor="PaleGoldenrod" />
                    <Columns>                      
                        <asp:BoundField DataField="id" HeaderText="ID" />
                        <asp:BoundField DataField="saltotal" HeaderText="SalTotal"  SortExpression="saltotal" />                  
                    <asp:TemplateField>                  
                    <FooterTemplate>
                        <asp:Label ID="lblTotal" runat="server"></asp:Label>
                    </FooterTemplate>
                    </asp:TemplateField>
                    </Columns>
                </asp:GridView>
             
            </td>
        </tr>
    </table>



C# Code:


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MySql.Data.MySqlClient;

public partial class GVSortPageingTotal : System.Web.UI.Page
{
    MySqlConnection cn = new MySqlConnection("server=localhost;database=gg;uid=root;pwd=root");
    decimal grdTotal = 0;
    static DataTable dt;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            fillgrid();
        }
    }
    void fillgrid()
    {
        MySqlDataAdapter da = new MySqlDataAdapter("select * from tbltotal", cn);
        dt = new DataTable();
        da.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            grdTotal = 0;
            // Below one line code With Bound Fields
            //decimal rowTotal = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "saltotal"));
            int i = 0;
            for (; i < GridView1.Rows.Count; i++)
            {
                decimal rowTotal = Convert.ToDecimal(GridView1.Rows[i].Cells[1].Text);
                grdTotal = grdTotal + rowTotal;
            }
            if (i < GridView1.PageSize)
            {
                decimal rowTotal = Convert.ToDecimal(dt.Rows[i].ItemArray[1].ToString());
                grdTotal = grdTotal + rowTotal;
            }
        }
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label lbl = (Label)e.Row.FindControl("lblTotal");
            lbl.Text = grdTotal.ToString("c");
        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        fillgrid();
    }
    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        string sortExpression = e.SortExpression;
        if (GridViewSortDirection == SortDirection.Ascending)
        {
            GridViewSortDirection = SortDirection.Descending;
            SortGridView(sortExpression, GridViewSortDirection.ToString());
        }
        else
        {
            GridViewSortDirection = SortDirection.Ascending;
            SortGridView(sortExpression, GridViewSortDirection.ToString());
        }
    }

    private void SortGridView(string sortExpression, string p)
    {
        DataView dv = new DataView(dt);
        dv.Sort = sortExpression;
        GridView1.DataSource = dv;
        GridView1.DataBind();
    }
    public SortDirection GridViewSortDirection
    {
        get
        {
            if (ViewState["sort"] == null)
                ViewState["sort"] = SortDirection.Ascending;
            return (SortDirection)ViewState["sort"];
        }
        set { ViewState["sort"] = value; }
    }
}

MAC Address of System

Step1 :---Add Namespace
        using System.Net.NetworkInformation;
Step2:-----Add Below Code in Your button Click Event

string macAddresses = "";
        foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
        {
            if (nic.OperationalStatus == OperationalStatus.Up)
            {
                macAddresses += nic.GetPhysicalAddress().ToString();
                break;
            }
        }      
        lblMsg.Text = macAddresses.ToString();

Sunday, September 18, 2011

Export Database table Data to Excel With Column Names


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;
using System.Data.SqlClient;
using NPOI.HSSF.UserModel;
using System.IO;


public partial class DataBasetoExcell : System.Web.UI.Page
{
    //OleDbConnection excelConnection = new OleDbConnection("database=Prasad;uid=sa;pwd=sa123;server=.;");
    SqlConnection strConnection = new SqlConnection("database=Prasad;uid=sa;pwd=sa123;server=.;");
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnDBtoExcell_Click(object sender, EventArgs e)
    {
        SqlDataAdapter daa = new SqlDataAdapter("select * from tblemp", strConnection);
        DataSet ds = new DataSet();
        daa.Fill(ds);

        Microsoft.Office.Interop.Excel.Application xlApp;
        Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
        Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
        object misValue = System.Reflection.Missing.Value;

        xlApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
        xlWorkBook = xlApp.Workbooks.Add(misValue);

        xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

        string tablename = string.Empty;
        for (int b = 0; b < ds.Tables.Count; b++)
        {
            tablename = ds.Tables[0].TableName.ToString();
        }
        for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; )
        {
            for (int j = 0; j <= ds.Tables[0].Columns.Count - 1; )
            {
                //Below 2 Lines With Data and Columns
                //string data = ds.Tables[0].Rows[i].ItemArray[j].ToString();
                //xlWorkSheet.Cells[i + 1, j + 1] = data.ToString();
                // Below Foreach Only Column Names
                foreach (DataColumn dc in ds.Tables[0].Columns)
                {
                    xlWorkSheet.Cells[0 + 1, j + 1] = dc.ColumnName.ToString();
                    i++;
                    j++;
                }
               
            }
        }

        xlWorkBook.SaveAs(@"C:\" + tablename, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
        xlWorkBook.Close(true, misValue, misValue);
        xlApp.Quit();

        releaseObject(xlWorkSheet);
        releaseObject(xlWorkBook);
        releaseObject(xlApp);



        SqlDataAdapter da = new SqlDataAdapter("insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=C:\\" + tablename + ";','SELECT * FROM [Sheet1$]') select * from tblemp ", strConnection);
        //SqlDataAdapter da = new SqlDataAdapter("select * from tblemp", strConnection);
        DataTable dt = new DataTable();
        da.Fill(dt);
    }



    private void releaseObject(object obj)
    {
        try
        {
            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
            obj = null;
        }
        catch (Exception ex)
        {
            obj = null;
            //MessageBox.Show("Exception Occured while releasing object " + ex.ToString());
        }
        finally
        {
            GC.Collect();
        }
    }
}

Saturday, September 17, 2011

Triggers


What is a Trigger

A trigger is a special kind of a store procedure that executes in response to certain action on the table like insertion, deletion or updation of data. It is a database object which is bound to a table and is executed automatically. You can’t explicitly invoke triggers.

Types Of Triggers

(i) After Triggers (For Triggers)
(ii) Instead Of Triggers 


(i) After Triggers

(a) AFTER INSERT Trigger.
(b) AFTER UPDATE Trigger.
(c) AFTER DELETE Trigger. 




(ii) Instead Of Triggers

These can be used as an interceptor for anything that anyonr tried to do on our table or view. If you define anInstead Of trigger on a table for the Delete operation, they try to delete rows, and they will not actually get deleted (unless you issue another delete instruction from within the trigger)
(a) INSTEAD OF INSERT Trigger.
(b) INSTEAD OF UPDATE Trigger.
(c) INSTEAD OF DELETE Trigger. 

Import and Export data from SQL Server 2005 to XL Sheet:

For uploading the data from Excel Sheet to SQL Server and viceversa, we need to create a linked server in SQL Server.

Procedure for creating a linked server in SQL Server 2005.

Expample linked server creation:

Before you executing the below command the excel sheet should be created in the specified path and it should contain the name of the columns.

EXEC sp_addlinkedserver 'ExcelSource2',
   'Jet 4.0',
   'Microsoft.Jet.OLEDB.4.0',
   'C:\Srinivas\Vdirectory\Testing\Marks.xls',
   NULL,
   'Excel 5.0'

Once you executed above query it will crate linked server in SQL Server 2005.

The following are the Query from sending the data from Excel sheet to SQL Server 2005.

INSERT INTO emp SELECT * from OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\text.xls','SELECT * FROM [sheet1$]')

The following query is for sending the data from SQL Server 2005 to Excel Sheet. 

insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=c:\text.xls;',
'SELECT * FROM [sheet1$]') select * from emp

These two queries are working fine.

Tuesday, September 6, 2011

Regular Expression Validator

File Upload Validation


<asp:FileUpload ID="FileUpload1" runat="server" />
    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
        ControlToValidate="FileUpload1" ErrorMessage="Fileupload"
        ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.doc|.docs|.jpg|.JPG|.gif|.GIF|.jpeg|.JPEG|.bmp|.BMP|.png|.PNG)$" 
        ValidationGroup="v"></asp:RegularExpressionValidator>

Small And Capital words and values in Textbox


<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
        ControlToValidate="TextBox2" ErrorMessage="Chars Caps and Smalls"
        ValidationExpression="\w[a-z,A-Z,0-9]*"></asp:RegularExpressionValidator>
<asp:Button ID="Button3" runat="server" Text="submit" />

Only Special Symbols in Textbox


<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
        ControlToValidate="TextBox2" ErrorMessage="Chars Caps and Smalls"
        ValidationExpression=".*[@#$%^&*/].*"></asp:RegularExpressionValidator>
<asp:Button ID="Button3" runat="server" Text="submit" />

Monday, September 5, 2011

Storing Data in Dynamic DataTable And Display in GridView


Source Code:

In Form Tag Write below source code



 <table align="center" class="style1">
        <tr>
            <td>
                &nbsp;</td>
            <td class="style2">
                F.Name</td>
            <td class="style3">
                <asp:TextBox ID="txtFName" runat="server"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td class="style2">
                L.Name</td>
            <td class="style3">
                <asp:TextBox ID="txtLName" runat="server"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td class="style2">
                Address</td>
            <td class="style3">
                <asp:TextBox ID="txtAddress" runat="server"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td class="style2">
                Phone</td>
            <td class="style3">
                <asp:TextBox ID="txtPhone" runat="server"></asp:TextBox>
            </td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td class="style2">
                &nbsp;</td>
            <td class="style3">
                <asp:Button ID="btnSave" runat="server" onclick="btnSave_Click" Text="Save" />
            </td>
            <td>
                <asp:Label ID="lblmsg" runat="server"></asp:Label>
            </td>
        </tr>
        <tr>
            <td align="center" colspan="4">
                <asp:GridView ID="GridView1" runat="server" BackColor="LightGoldenrodYellow"
                    BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black"
                    GridLines="None">
                    <FooterStyle BackColor="Tan" />
                    <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
                        HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
                    <HeaderStyle BackColor="Tan" Font-Bold="True" />
                    <AlternatingRowStyle BackColor="PaleGoldenrod" />
                </asp:GridView>
            </td>
        </tr>
    </table>


C# Code:



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class DynamicDataTable : System.Web.UI.Page
{
    static int i=1;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataTable dt = new DataTable();
            DataColumn dtcol = new DataColumn("Id", typeof(System.Int32));
            dtcol.AutoIncrement = true;
            dt.Columns.Add(dtcol);
            dtcol = new DataColumn("FName", typeof(System.String));
            dt.Columns.Add(dtcol);
            dtcol = new DataColumn("LName", typeof(System.String));
            dt.Columns.Add(dtcol);
            dtcol = new DataColumn("Address", typeof(System.String));
            dt.Columns.Add(dtcol);
            dtcol = new DataColumn("Phone", typeof(System.String));
            dt.Columns.Add(dtcol);
            int j = form1.Controls.Count;
            Session["datatable"] = dt;
            if (Session["dt"] != null)
            {
                GridView1.DataSource = Session["dt"].ToString();
                GridView1.DataBind();
            }
            else
            {
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        DataTable dtt = (DataTable)Session["datatable"];
        DataRow dr = dtt.NewRow();
        dr[0] = i++;
        dr[1] = txtFName.Text;
        dr[2] = txtLName.Text;
        dr[3] = txtAddress.Text;
        dr[4] = txtPhone.Text;
        dtt.Rows.Add(dr);
        Session["id"] = dtt.ToString();
        GridView1.DataSource = dtt;
        GridView1.DataBind();
        lblmsg.Text = "Inserted Successfully..." + dr[0].ToString() + "Records";
    }
}

DropdownList And CheckboxList C sharp Validation


   Source Code

 <asp:CheckBoxList ID="CheckBoxList1" runat="server">
        <asp:ListItem>AA</asp:ListItem>
        <asp:ListItem>BB</asp:ListItem>
        <asp:ListItem>CC</asp:ListItem>
        <asp:ListItem>DD</asp:ListItem>
    </asp:CheckBoxList>
    <asp:RadioButtonList ID="RadioButtonList1" runat="server">
    <asp:ListItem Text="Male" Value="0"></asp:ListItem>
    <asp:ListItem Text="FeMale" Value="1"></asp:ListItem>
    </asp:RadioButtonList>


<asp:Button ID="btnOK" runat="server" Text="OK" onclick="btnOK_Click"
        ValidationGroup="k" />
    <asp:Label ID="Label1" runat="server"></asp:Label>
    <asp:Label ID="Label2" runat="server"></asp:Label>



C# Code

 protected void btnOK_Click(object sender, EventArgs e)
    {
        foreach (ListItem li in CheckBoxList1.Items)
        {
            if (li.Selected)
            {

            }
            else
            {
                Label2.Text = "Pls Select CheckBoxList";
            }
        }
        foreach (ListItem l in RadioButtonList1.Items)
        {
            if (l.Selected)
            {
            }
            else
            {
                Label1.Text = "Pls Select RadioButtonList";
            }
        }
    }

Saturday, September 3, 2011

Add Database colomn names to DropDownlist using c#


Step1) Take Name Space

using System.Data.SqlClient;

Step2) give the connection to database

SqlConnection cn = new SqlConnection("server=.;database=dbname;uid=root;pwd=root");

Step3)Write below code in Page_Load



 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            MySqlDataReader dr;
            MySqlCommand cmd = new MySqlCommand("select RoomsID as rID,HostelID as hID,BuildingID as bID,FloorID as fID,RoomName as rname,AvailableBeds as Abeds,Status as ST from tblhostelrooms", cn);
            cn.Open();
            dr = cmd.ExecuteReader();
            for (int i = 0; i < dr.FieldCount; i++)
            {
                DropDownList1.Items.Add(dr.GetName(i));
            }
            cn.Close();
        }
    }

AJAX Interview Questions And Answers


What Is The Role Of ScriptManager In Ajax?


ScriptManager class is the heart of ASP.NET Ajax. Before elaborating more on ScriptManager, note that ScriptManager is class and a control (both) in Ajax. 
The ScriptManager class in ASP.NET manages Ajax Script Libraries, partial page rendering functionality and client proxy class generation for webapplications and services.




1)What is the use of DisplayAfter Property of UpdateProgress Control ASP.NET AJAX?


Ans:DisplayAfter  property of UpdateProgress Control is used to set the time after the loading image is displayed once the Ajax request is sent.


2)Can We have nested Update Panels one inside another in ASP.NET AJAX?


Ans:Yes ! we can have one update panel inside another.


3)What is the use of Update Progress Control in ASP.NET AJAX?


Ans:Update Progress Control is mostly used to show loading image or message while async postback is going on.


4)what is meant by update mode conditional in ASP.NET UpdatePanel?


Ans:suppose There are two update panels on the page say Panel1 and Panel2.then if A button placed in Panel1 is clicked, Panel2 will also get updated.To stop this we should use Update Mode Conditional for both the Update panels.Also set ChildrenAs Triggers as true.


5)How many update panel we can have per page in ASP.NET?


Ans:As many as we want.There is no such limit.


6)What is prerequisite for Update Panel use?


Ans:Script Manager is prerequisite for Update Panel use.


7)What are the different controls provided in ASP.NET Ajax Framework 1.0?


Ans:a)Script Manager 

b)Script Manager Proxy

c)Update Panel

d)Update Progress

e)Timer


8)Name the different types of readyStates in Ajax?

Ans:a)request not initialized

b)request set

c)request sent

d)request processing

e)request completed


9)Can we implement Ajax in browsers that do not support the XmlHttpRequest object?

Ans:Yes,remote scripts can be used for this purpose.

10)Name the browsers that support XmlHttpRequest object?

Ans:a)Internet Explorer 5.0+

b)Mozilla 1.0+/Firefox

c)Safari 1.2+

d)Opera 8.0 +

Friday, September 2, 2011

C# Interview Questions And Answers


Difference Between Http And Https ?

Ans:-- What i know is http is hyper text transfer protocol which is responsible for transmitting and receiving information across the Internet where as https is secure http, which is used exchanging confidential information with a server, which needs to be secured in order to prevent unauthorized access.


What is DLL Hell in C sharp?

Ans:-DLL HELL is the problem that occures when an installation 
of a newer application might break or hinder other 
application as newer DLLs are copied into the system and 
the older application do not support or not compatible with 
them. .net overcomes this problem by supporting multiple 
versions of an assembly at any given time.this is called 
side-by-side component versioning.


1)When a child class is instantiated base class or child class constructor will be called first?

Ans:Base class constructor will be called first When a child class is instantiated.

2)Can a child class constructor call the base class constructor?

Ans:Yes, a child class constructor call the  base class constructor using the base keyword.

3)Can we overload a constructor in C#?

Ans:yes we can overload a constructor in C# same as having more than one constructor in a class.

4)Can static classes have constructors in C#?

Ans:yes static classes have constructors in C#.

5)can we have static constructors in C#?

Ans:Yes we can have static constructors in C# 

It is called automatically before any static members are accessed or first object of the class is created.

6)What is the use of private constructor in c#?

Ans:Private constructor prevents the creation of object of the class outside the class.

One of its use is to create singleton design pattern

where object is created inside the class and then

that object is accessed using class name.

public  class MyTestClass

{
    public static MyTest MyObj = new MyTestClass();  

    private MyTestClass()

    {

     //initialize variables

    }

}

static void Main()

{

 MyTestClass MyTestObj = MyTestClass.MyObj;

}

7)Can we have a constructor as private in C#?

Ans:Yes we can have a private constructor in C#.

8)Can we have more than one constructor in a c# class?

Ans:Yes we can have more than one constructor in a c# class.

9)can we overload and override static methods in C#?

Ans:we can overload the static methos but cannot override.

10)can Static methods and properties access non-static fields and events in C#?

Ans:No Static methods and properties cannot access non-static fields and events in their containing
       Type.

11)