Introduction
ReportViewer is a freely redistributable control that enables embedding reports in applications developed using the .NET Framework. Reports are designed with drag-and-drop simplicity using Report Designer included in Visual Studio 2008 (Standard editon and above.)
The ReportViewer control offers the following benefits:
1 Processes data efficiently. The reporting engine built into ReportViewer can perform operations such as filtering, sorting, grouping and aggregation.
2 Supports a variety of ways in which to present data. You can present data as lists, tables, charts and matrices (also known as crosstabs.)
3 Adds visual appeal. You can specify fonts, colors, border styles, background images etc to make your report visually appealing.
4 Enables interactivity in reports. You can have collapsible sections, document map, bookmarks, interactive sorting etc in your report.
5 Supports conditional formatting. You can embed expressions in the report to change display style dynamically based on data values.
6 Supports printing and print preview.
7 Supports export to Excel and PDF.
The control can process and render reports independently using a built-in engine ('local mode') or it can display reports that are processed and rendered on a Report Server ('remote mode').
There is a WinForms and a WebForms version of the control.
Monday, August 10, 2009
Saturday, August 8, 2009
JavaScript Debugging and Intellisense
In Visual Studio 2008, client-side JavaScript has now become a first-class citizen in regards to its debugging and Intellisense support. Not only does the Intellisense give standard JavaScript keyword support, but it will automatically infer variable types and provide method, property and event support from any number of included script files. Similarly, the JavaScript debugging support now allows for the deep Watch and Locals support in JavaScript that you are accustomed to having in other languages in Visual Studio. And despite the dynamic nature of a lot of JavaScript, you will always be able to visualize and step into the JavaScript code, no matter where it is generated from. This is especially convenient when building ASP.NET AJAX applications
New Features in ASP.NET 3.5
ASP.NET AJAX
With ASP.NET AJAX, developers can quickly create pages with sophisticated, responsive user interfaces and more efficient client-server communication by simply adding a few server controls to their pages. Previously an extension to the ASP.NET runtime, ASP.NET AJAX is now built into the platform and makes the complicated task of building cross-platform, standards based AJAX applications easy.
With ASP.NET AJAX, developers can quickly create pages with sophisticated, responsive user interfaces and more efficient client-server communication by simply adding a few server controls to their pages. Previously an extension to the ASP.NET runtime, ASP.NET AJAX is now built into the platform and makes the complicated task of building cross-platform, standards based AJAX applications easy.
Wednesday, August 5, 2009
ASP.NET SQL Server Registration Tool (Aspnet_regsql.exe)
The ASP.NET SQL Server Registration tool is used to create a Microsoft SQL Server database for use by the SQL Server providers in ASP.NET, or to add or remove options from an existing database.
You can run Aspnet_regsql.exe without any command-line arguments to run a wizard that will walk you through specifying connection information for your SQL Server installation, and installing or removing the database elements for the membership, role management, profile, Web Parts personalization, and health monitoring features. (Setting session state and SQL cache dependency are not covered by the wizard.) You can also run Aspnet_regsql.exe as a command-line tool to specify database elements for individual features to add or remove, using the options listed in the table below
Aspnet_regsql.exe SQL Connection OptionsOption Description
-? Prints Aspnet_regsql.exe Help text in the command window. -W Runs the tool in wizard mode. This is the default if no command-line arguments are specified.
-C Specifies the connection string to the computer running SQL Server where the database will be installed, or is already installed. This option is not necessary if you specify only the server (-S) and login (-U and -P, or -E) information.
-S Specifies the name of the computer running SQL Server where the database will be installed, or is already installed.
-U The SQL Server user ID to log in with. This option also requires the password (-P) option. This option is not necessary if you are authenticating using Windows credentials (-E).
-P The SQL Server password to log in with. This option also requires the user ID (-U) option. This option is not necessary if you are authenticating using Windows credentials (-E).
-E Authenticates using the Windows credentials of the currently logged-on user.
-sqlexportlonly Generates a SQL script file that can be used to add or remove the specified features. The specified actions are not performed.
Application Services Options
Adds support for one or more ASP.NET application services. Service identifiers can be specified together or separately. The following identifiers are used for ASP.NET application services:
-A allmrpcw
all - All services, including common tables and stored procedures shared by the services
m - Membership
r - Role Manager
p - Profile
c - Web Parts Personalization
Removes support for one or more application services. Service identifiers can be specified together or separately. The following identifiers are used for ASP.NET application services:
-R allmrpcw
m - Membershipr - Role Managerp - Profilec - Web Parts Personalizationw - Web Events
-Q Runs the tool in quiet mode and does not confirm before removing an application service.-d Specifies the name of the database to create or modify for use with application services. If the database is not specified, the default database name of "aspnetdb" is used.
Note
The database elements that are installed in the application services database will always be owned by the SQL Server database owner account (dbo). You do not need to be a system administrator for the computer running SQL Server to install the application services database. To install the application services database, a SQL Server login must be permitted to the db_ddladmin and dd_securityadmin roles for the SQL Server database.
SQL Cache Dependency Options (for Microsoft SQL Server 7.0, Microsoft SQL Server 2000 and SQL Server 2005)
Option Description
-d Specifies the name of the database to use with SQL cache dependency. The database can optionally be specified using the connection string option, -C.
-ed Enables a database for SQL cache dependency.-dd Disables a database for SQL cache dependency.-et Enables a table for SQL cache dependency. The -t option must also be included in the parameter string.-dt Disables a table for SQL cache dependency. The -t option must also be included in the parameter string.-t Specifies the table name to enable or disable for use with SQL cache dependency. This option must be used with the -et or -dt options.-lt Lists all tables enabled for SQL cache dependency.
Session State Options
Option Description -d Specifies the name of the database to store session state. This option must be used if -sstype is set to c-ssadd Adds support for SQL Server mode session state.-ssremove Removes support for SQL Server mode session state.
Specifies the type of session state to us1:
-sstype tpc
t - Temporary. Session state data is stored in the SQL Server tempdb database. Stored procedures for managing session state are installed in the SQL Server ASPState database. Data is not persisted if you restart SQL. This is the default.
p - Persisted. Both session state data and stored procedures are stored in the SQL Server ASPState database.
c - Custom. Both session state data and stored procedures are stored in a custom database. The database name must be specified using the -d option.
You can run Aspnet_regsql.exe without any command-line arguments to run a wizard that will walk you through specifying connection information for your SQL Server installation, and installing or removing the database elements for the membership, role management, profile, Web Parts personalization, and health monitoring features. (Setting session state and SQL cache dependency are not covered by the wizard.) You can also run Aspnet_regsql.exe as a command-line tool to specify database elements for individual features to add or remove, using the options listed in the table below
Aspnet_regsql.exe SQL Connection OptionsOption Description
-? Prints Aspnet_regsql.exe Help text in the command window. -W Runs the tool in wizard mode. This is the default if no command-line arguments are specified.
-C Specifies the connection string to the computer running SQL Server where the database will be installed, or is already installed. This option is not necessary if you specify only the server (-S) and login (-U and -P, or -E) information.
-S Specifies the name of the computer running SQL Server where the database will be installed, or is already installed.
-U The SQL Server user ID to log in with. This option also requires the password (-P) option. This option is not necessary if you are authenticating using Windows credentials (-E).
-P The SQL Server password to log in with. This option also requires the user ID (-U) option. This option is not necessary if you are authenticating using Windows credentials (-E).
-E Authenticates using the Windows credentials of the currently logged-on user.
-sqlexportlonly Generates a SQL script file that can be used to add or remove the specified features. The specified actions are not performed.
Application Services Options
Adds support for one or more ASP.NET application services. Service identifiers can be specified together or separately. The following identifiers are used for ASP.NET application services:
-A allmrpcw
all - All services, including common tables and stored procedures shared by the services
m - Membership
r - Role Manager
p - Profile
c - Web Parts Personalization
Removes support for one or more application services. Service identifiers can be specified together or separately. The following identifiers are used for ASP.NET application services:
-R allmrpcw
m - Membershipr - Role Managerp - Profilec - Web Parts Personalizationw - Web Events
-Q Runs the tool in quiet mode and does not confirm before removing an application service.-d Specifies the name of the database to create or modify for use with application services. If the database is not specified, the default database name of "aspnetdb" is used.
Note
The database elements that are installed in the application services database will always be owned by the SQL Server database owner account (dbo). You do not need to be a system administrator for the computer running SQL Server to install the application services database. To install the application services database, a SQL Server login must be permitted to the db_ddladmin and dd_securityadmin roles for the SQL Server database.
SQL Cache Dependency Options (for Microsoft SQL Server 7.0, Microsoft SQL Server 2000 and SQL Server 2005)
Option Description
-d Specifies the name of the database to use with SQL cache dependency. The database can optionally be specified using the connection string option, -C.
-ed Enables a database for SQL cache dependency.-dd Disables a database for SQL cache dependency.-et Enables a table for SQL cache dependency. The -t option must also be included in the parameter string.-dt Disables a table for SQL cache dependency. The -t option must also be included in the parameter string.-t Specifies the table name to enable or disable for use with SQL cache dependency. This option must be used with the -et or -dt options.-lt Lists all tables enabled for SQL cache dependency.
Session State Options
Option Description -d Specifies the name of the database to store session state. This option must be used if -sstype is set to c-ssadd Adds support for SQL Server mode session state.-ssremove Removes support for SQL Server mode session state.
Specifies the type of session state to us1:
-sstype tpc
t - Temporary. Session state data is stored in the SQL Server tempdb database. Stored procedures for managing session state are installed in the SQL Server ASPState database. Data is not persisted if you restart SQL. This is the default.
p - Persisted. Both session state data and stored procedures are stored in the SQL Server ASPState database.
c - Custom. Both session state data and stored procedures are stored in a custom database. The database name must be specified using the -d option.
Enable or Disable Asp.net validation control using JavaScript
function EnableValidator()
{
var dropdownValue = document.getElementById("").value;
if(dropdownValue == 2)
{
ValidatorEnable(document.getElementById(''),true);
}
else
{
ValidatorEnable(document.getElementById(''),false);
}
}
{
var dropdownValue = document.getElementById("").value;
if(dropdownValue == 2)
{
ValidatorEnable(document.getElementById(''),true);
}
else
{
ValidatorEnable(document.getElementById(''),false);
}
}
Increase the buffer limit
To increase the buffering limit, follow these steps:1.Click Start, click Run, type cmd, and then click OK.2.Type the following command, and then press ENTER:cd /d %systemdrive%\inetpub\adminscripts3.Type the following command, and then press ENTER:cscript.exe adsutil.vbs SET w3svc/aspbufferinglimit LimitSizeNote LimitSize represents the buffering limit size in bytes. For example, the number 67108864 sets the buffering limit size to 64 MB.To confirm that the buffer limit is set correctly, follow these steps:1.Click Start, click Run, type cmd, and then click OK.2.Type the following command, and then press ENTER:cd /d %systemdrive%\inetpub\adminscripts3.Type the following command, and then press ENTER:cscript.exe adsutil.vbs GET w3svc/aspbufferinglimit
Read Data From an Excel File (.xlsx) in ASP.NET
In this article, we will see how to display data from an Excel spreadsheet using ASP.NET. We will connect to a Microsoft Excel workbook using the OLEDB.NET data provider, extract data and then display the data in a GridView. Let us get started.
Step 1: Open Visual Studio > File > New >Website > Under Templates, click ASP.NET WebSite and choose either Visual C# or Visual Basic as the language. Select a location and click Ok.
Step 2: We will create two excel sheets and add them to the project. One excel sheet will be created in Office 2003(.xls) and the other one using Office 2007(.xlsx). Add 4 columns called EID, EName, Age and City to the Sheet1. Also add some data into the columns. Once these excel files are created, add them to your project. To add them to the project, right click project > Add Existing Item > Add the two excel files.
Step 3: We will now create a web.config file to store the connection string information. Right click project > Add New Item > Web.config. Add the following entries to the file
As you can observe, the connection string for xlsx (Excel 2007) contains Microsoft.ACE.OLEDB.12.0 as the provider. This is the new Access database engine OLE DB driver and is also capable of reading Excel 2003.
Step 4: Add a GridView to the Default.aspx page. We will extract data from the excel file and bind it to the GridView.
Step 5: Let us now create a connection to the excel file and extract data from it. Before that add a reference toSystem.Data.OleDb;
C#protected void Page_Load(object sender, EventArgs e){string connString = ConfigurationManager.ConnectionStrings["xls"].ConnectionString;// Create the connection objectOleDbConnection oledbConn = new OleDbConnection(connString);try{// Open connectionoledbConn.Open();
// Create OleDbCommand object and select data from worksheet Sheet1OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", oledbConn);
// Create new OleDbDataAdapterOleDbDataAdapter oleda = new OleDbDataAdapter();
oleda.SelectCommand = cmd;
// Create a DataSet which will hold the data extracted from the worksheet.DataSet ds = new DataSet();
// Fill the DataSet from the data extracted from the worksheet.oleda.Fill(ds, "Employees");
// Bind the data to the GridViewGridView1.DataSource = ds.Tables[0].DefaultView;GridView1.DataBind();}catch{}finally{// Close connectionoledbConn.Close();}
}
VB.NET
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)Dim connString As String = ConfigurationManager.ConnectionStrings("xls").ConnectionString' Create the connection objectDim oledbConn As OleDbConnection = New OleDbConnection(connString)Try' Open connectionoledbConn.Open()
' Create OleDbCommand object and select data from worksheet Sheet1Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [Sheet1$]", oledbConn)
' Create new OleDbDataAdapterDim oleda As OleDbDataAdapter = New OleDbDataAdapter()
oleda.SelectCommand = cmd
' Create a DataSet which will hold the data extracted from the worksheet.Dim ds As DataSet = New DataSet()
' Fill the DataSet from the data extracted from the worksheet.oleda.Fill(ds, "Employees")
' Bind the data to the GridViewGridView1.DataSource = ds.Tables(0).DefaultViewGridView1.DataBind()CatchFinally' Close connectionoledbConn.Close()End Try
End Sub
Note:if you want to select a particular column from the excel sheet then you have to assign the name of the column at top of every column. Do not use the excel column name like A1, B1 etc...
All set!! Run the application and see the data getting displayed in the GridView. If you want to target the Excel 2007 sheet, just change xls to xlsx in the ConfigurationManager.ConnectionString.
Step 1: Open Visual Studio > File > New >Website > Under Templates, click ASP.NET WebSite and choose either Visual C# or Visual Basic as the language. Select a location and click Ok.
Step 2: We will create two excel sheets and add them to the project. One excel sheet will be created in Office 2003(.xls) and the other one using Office 2007(.xlsx). Add 4 columns called EID, EName, Age and City to the Sheet1. Also add some data into the columns. Once these excel files are created, add them to your project. To add them to the project, right click project > Add Existing Item > Add the two excel files.
Step 3: We will now create a web.config file to store the connection string information. Right click project > Add New Item > Web.config. Add the following entries to the file
As you can observe, the connection string for xlsx (Excel 2007) contains Microsoft.ACE.OLEDB.12.0 as the provider. This is the new Access database engine OLE DB driver and is also capable of reading Excel 2003.
Step 4: Add a GridView to the Default.aspx page. We will extract data from the excel file and bind it to the GridView.
Step 5: Let us now create a connection to the excel file and extract data from it. Before that add a reference toSystem.Data.OleDb;
C#protected void Page_Load(object sender, EventArgs e){string connString = ConfigurationManager.ConnectionStrings["xls"].ConnectionString;// Create the connection objectOleDbConnection oledbConn = new OleDbConnection(connString);try{// Open connectionoledbConn.Open();
// Create OleDbCommand object and select data from worksheet Sheet1OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", oledbConn);
// Create new OleDbDataAdapterOleDbDataAdapter oleda = new OleDbDataAdapter();
oleda.SelectCommand = cmd;
// Create a DataSet which will hold the data extracted from the worksheet.DataSet ds = new DataSet();
// Fill the DataSet from the data extracted from the worksheet.oleda.Fill(ds, "Employees");
// Bind the data to the GridViewGridView1.DataSource = ds.Tables[0].DefaultView;GridView1.DataBind();}catch{}finally{// Close connectionoledbConn.Close();}
}
VB.NET
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)Dim connString As String = ConfigurationManager.ConnectionStrings("xls").ConnectionString' Create the connection objectDim oledbConn As OleDbConnection = New OleDbConnection(connString)Try' Open connectionoledbConn.Open()
' Create OleDbCommand object and select data from worksheet Sheet1Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [Sheet1$]", oledbConn)
' Create new OleDbDataAdapterDim oleda As OleDbDataAdapter = New OleDbDataAdapter()
oleda.SelectCommand = cmd
' Create a DataSet which will hold the data extracted from the worksheet.Dim ds As DataSet = New DataSet()
' Fill the DataSet from the data extracted from the worksheet.oleda.Fill(ds, "Employees")
' Bind the data to the GridViewGridView1.DataSource = ds.Tables(0).DefaultViewGridView1.DataBind()CatchFinally' Close connectionoledbConn.Close()End Try
End Sub
Note:if you want to select a particular column from the excel sheet then you have to assign the name of the column at top of every column. Do not use the excel column name like A1, B1 etc...
All set!! Run the application and see the data getting displayed in the GridView. If you want to target the Excel 2007 sheet, just change xls to xlsx in the ConfigurationManager.ConnectionString.
Subscribe to:
Posts (Atom)