Friday, August 31, 2012

Connection String From Web.config in Class file (Three Tire Architecture)

Here I will explain How to retrieve Connection String from Web.config in Class.cs file when using Three Tire Architecture or More Tires. Here in 3 tire...
  • UI Validation (ASP.Net)            //ASP.Net web application
  • BLL (Business Logic Layer)     //Windows - Class Library project
  • DAL (Data Access Layer)         //Windows - Class Library project
 Here we had TWO ways to get connection string from we.config file.

  • In 1st method we can get connection string in web.config file from
    <connectionStrings/> tag i.e.,
     
    <connectionStrings> 
    <add name="constring"
         connectionString="server=(local)\SQLEXPRESS; 
         database=sampleDB; 
         user id=sa; 
         pwd=*********;" />
     </connectionStrings> 
     
    and now we need to add reference
     
    System.Configuration.dll
     
    and the connection string can be written as shown below
     
    private string constring = 
           ConfigurationManager.ConnectionStrings["constring"].ToString();
  • In 2nd method write the connection string as shown below<configuration> 
    <appSettings>
    <add key="constring" 
    value="server=(local)\SQLEXPRESS;
    database=sampleDB;
    user id=sa;
    pwd=*********;"/>    
    </appSettings>
    </configuration> 

    and Now in the DataAccessLayer i.e, in the class file write as shown below.
    Before that you need to add  

    using System.Configuration;

    and now

    private string constring = 
            ConfigurationSettings.AppSettings["constring"].ToString();
     
For ThreeTite architecture Click HERE

How to use While Loop In StoredProcedures

Here I will explain how to use while loop in Stored Procedures. Mostly we will use while loop in stored procedures.
Here is the sample stored procedure to print 1 to 5 using while loop.

Ex : 1

create proc whileLoop
as
begin

declare @I int = 1, @J int = 5 -- Declare i, J and assign values

while(@I <= @J)
begin

print @I

set @I = @I + 1;

end

end

and now to execute the above stored procedure write the below line and select if the line is in the sample script file and press F5


exec whileLoop


Out Put :

1
2
3
4
5

How to use MsChart in Asp.Net Using c#

Here i am going to explain how to use MsCharts in Asp.Net using C#.Net  and DataSet's




Thursday, August 30, 2012

Export gridview data to Word using asp.net using C#

Here i will explain How to Export Gridview Data To Word. While Exporting I will explain the problems how to solve them. First download the ItextSharp from the above link.

Previously Explained 

  • Export Gridview Data To PDF          ClickHere 
  • Export Gridview Data To Excel        ClickHere 

 And Now i will Explain As the Title Says

         protected void btnExpToWord_Click(object sender, EventArgs e)
        {
            try
            {
                ExpGvToExcelControl.AllowPaging = false;
                BindGrid();
                Response.ClearContent();
                Response.AddHeader("content-disposition", 

                             string.Format("attachment; filename={0}", "EmpInfo.doc"));
                Response.Charset = "";
                Response.ContentType = "application/ms-word";
                StringWriter sw = new StringWriter();
                HtmlTextWriter htw = new HtmlTextWriter(sw);
                ExpGvToExcelControl.RenderControl(htw);
                Response.Write(sw.ToString());
                Response.End();
            }
            catch (Exception ex)
            {
                string ErrMsg = ex.Message;
            }
        }








Export gridview data to Excel using asp.net using C#

Here i will explain How to Export Gridview Data To Excel. In the Previous post Explained How to Export Gridview Data To PDF  and now While Exporting I will explain the problems how to solve them. Here i am binding Gridview In the Page_Load event 

Out Put :


Control 'gvdetails' of type 'GridView' must be placed inside a form tag with runat=server


Control 'gvdetails' of type 'GridView' must be placed inside a form tag with runat=server

For the above type of Error Write the following Method in the code behind file.

        
        public override void VerifyRenderingInServerForm(Control control)
        {
            // verifies the control is rendered here
        }

How to Add multiple Headers to gridview in Asp.Net using C#


Hear i am going to explain how to add multiple Headers to Gridview in ASp.Net using C#
as shown below two examples...







Wednesday, August 29, 2012

Export gridview data to PDF using asp.net using C#

Here i will explain How to Export Gridview Data To PDF using ITextSharp. While Exporting I will explain the problems how to solve them. First download the ItextSharp from the above link.

Here i am binding Gridview In the Page_Load event



Out Put :






Sunday, August 26, 2012

Saturday, August 4, 2012

Plain text as watermark for password text box using

In this post i will how to use Plain Text as Watermark for password TextBox in asp.net.

In the other post i was explained ASP.NET textbox with jQuery UI DatePicker 


Code in ASPX page