Thursday, April 24, 2008

Selecting checkbox in gridview and select values from gridview rows





CheckBox ch = (CheckBox)GridView1.HeaderRow.FindControl("CheckBox1");
if (ch.Checked == true)
{
foreach (GridViewRow gv in GridView1.Rows)
{
ch2 = (CheckBox)gv.FindControl("CheckBox2");

ch2.Checked = true;
string workordernum = gv.Cells[1].Text;
string name = gv.Cells[2].Text;
string dept = gv.Cells[3].Text;
string workorder = gv.Cells[4].Text;
string equipment = gv.Cells[5].Text;
string worktype = gv.Cells[6].Text;
con.Open();
Label6.Text = "insert into jobapprove values('" + Label5.Text.ToString() + "','" + workordernum.ToString() + "','" + name.ToString() + "','" + dept.ToString() + "','" + workorder.ToString() + "','" + equipment.ToString() + "','" + worktype.ToString() + "')";
SqlCommand cmdd = new SqlCommand("insert into jobapprove values('" + Label5.Text.ToString() + "','" + workordernum.ToString() + "','" + name.ToString() + "','" + dept.ToString() + "','" + workorder.ToString() + "','" + equipment.ToString() + "','" + worktype.ToString() + "')", con);
cmdd.ExecuteNonQuery();
con.Close();
}
}
if (ch.Checked == false )
{
foreach (GridViewRow gv in GridView1.Rows)
{
ch2 = (CheckBox)gv.FindControl("CheckBox2");
ch2.Checked = false;
}
}


Coding For selecting Entire Checkbox while selecting Checkbox in Gridview HeaderRow

ch = (CheckBox)GridView1.HeaderRow.FindControl("CheckBox2");
foreach (GridViewRow gr in GridView1.Rows)
{
if (ch.Checked == true)
{
CheckBox ch1 = (CheckBox)gr.FindControl("CheckBox1");
ch1.Checked = true;
}
else if (ch.Checked == false)
{
CheckBox ch1 = (CheckBox)gr.FindControl("CheckBox1");
ch1.Checked = false;
}

}

Friday, April 18, 2008

Send a Parameter from a form to show in Report Viewer

Things are do before running this from






using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page

{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=vijay;Integrated Security=True");
private ReportDocument rep=new ReportDocument ();
//protected override void unload(object sender, EventArgs e)
//{
// base.OnUnload(e);
// this.Unload += new EventHandler(Page.Unload);
//}
protected void page_unload()
{
rep.Clone();
rep.Dispose();
}
protected void Page_Load(object sender, EventArgs e)
{rep.Load (Server.MapPath ("CrystalReport1.rpt"));
rep.FileName = Server.MapPath("CrystalReport1.rpt");
if (!IsPostBack)

{
binddata();
}

}
public void binddata()
{
SqlDataAdapter dr = new SqlDataAdapter("select * from sample", con);
DataSet ds = new DataSet();
dr.Fill(ds);
DropDownList1.DataSource = ds;
DropDownList1.Items.Insert(0, "Select");
DropDownList1.DataTextField = "username";
DropDownList1.DataValueField = "username";
DropDownList1.DataBind();

DropDownList2.DataSource = ds;
DropDownList2.Items.Insert(0, "Select");
DropDownList2.DataTextField = "num";
DropDownList2.DataValueField = "num";
DropDownList2.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
Button1.Text = "Connect";
//string name = DropDownList1.SelectedValue.ToString();
//int num = Convert.ToInt32(DropDownList2.SelectedValue);
if (Button1.Text == "Connect")
{
Button1.Text = "View Report";
string name = TextBox1.Text;
int num = Convert.ToInt32(TextBox2.Text.ToString());
rep.SetParameterValue("name", name);
rep.SetParameterValue("num", num);
CrystalReportViewer1.ReportSource = rep;
}
}
}

Wednesday, March 26, 2008

Text To Speech

Download and install the Microsoft Speech SDK
Create a new project in Visual Studio
Add a reference to the Microsoft Speech Object Library COM object
Use the following code to record your speech to a .wav file…


SpeechLib.SpFileStream SpeechFileStream;
SpeechFileStream = new SpeechLib.SpFileStreamClass();
SpeechFileStream.Open(@"c:\test.wav", SpeechLib.SpeechStreamFileMode.SSFMCreateForWrite, false);
SpeechLib.SpVoice spv = new SpeechLib.SpVoice();
spv.AudioOutputStream = SpeechFileStream;
spv.Speak("I'm alive!", SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault);
SpeechFileStream.Close();

PDF creation using c#.net

PDFCreatorPilot3Lib.PDFDocument3Class PDF = new PDFCreatorPilot3Lib.PDFDocument3Class();

// initialize PDF Engine

PDF.StartEngine("demo@demo", "demo");

// set filename

PDF.FileName = "TestCSHARP.PDF";

PDF.AutoLaunch = true; // auto-open generated pdf document

// start document generation

PDF.BeginDoc();

// draw "HELLO, PDF" message on the current PDF page

PDF.PDFPAGE_SetActiveFont("Verdana", true, false, false, false, 14, 0);

PDF.PDFPAGE_TextOut(10, 20, 0, "HELLO, PDF!");

// finalize document generation

PDF.EndDoc();

Types of Normalizations

1NF: Eliminate Repeating Groups

Make a separate table for each set of related attributes, and give each table a primary key. Each field contains at most one value from its attribute domain.

2NF: Eliminate Redundant Data

If an attribute depends on only part of a multi-valued key, remove it to a separate table.

3NF: Eliminate Columns Not Dependent On Key

If attributes do not contribute to a description of the key, remove them to a separate table. All attributes must be directly dependent on the primary key

BCNF: Boyce-Codd Normal Form

If there are non-trivial dependencies between candidate key attributes, separate them out into distinct tables.

4NF: Isolate Independent Multiple Relationships

No table may contain two or more 1:n or n:m relationships that are not directly related.

5NF: Isolate Semantically Related Multiple Relationships

There may be practical constrains on information that justify separating logically related many-to-many relationships.


ONF: Optimal Normal Form

A model limited to only simple (elemental) facts, as expressed in Object Role Model notation.

DKNF: Domain-Key Normal Form
A model free from all modification anomalies.

Remember, these normalization guidelines are cumulative. For a database to be in 3NF, it must first fulfill all the criteria of a 2NF and 1NF database.

sending mail from Sql Server 2005

step1 Enable the Database Mail feature on Sql Server 2005 with the following Statements.

USE MASTER
GO
SP_CONFIGURE 'SHOW ADVANCED OPTIONS',1
GO
RECONFIGURE WITH OVERRIDE
GO
SP_CONFIGURE 'DATABASE MAIL XPS',1
GO
RECONFIGURE
GO


step 2. Using the sysmail_add_account procedure to Create Database account .

EXECUTE msdb.dbo.sysmail_add_account_sp
@account_name = 'Admin', -- Account Name on SMTP (User Defined)
@description = 'Mail Account for Database Mail',-- Account mail description. (User Defined)
@email_address = 'shivaraj.gk@gmail.com',-- Mail sender E-mail address (User Defined)
@display_name = ‘Admin', -- Mail Sender display name, which displays, when mail received by recipient (User Defined)
@username=’ ’, -- SMTP Sever User Name
@password='', -- SMTP Server Password
@mailserver_name = '190.160.110.50' -- SMTP Server Address.




Step3: Using the sysmail_add_profile procedure to create a Database Mail profile.
EXECUTE msdb.dbo.sysmail_add_profile_sp
@profile_name = 'XXXXXXXX' –-Profile Name to add on SMTP Server(User Defined)
@description = 'Profile used for Database Mail'--Profile Description (User Defined)



Step4: Now execute the sysmail_add_profileaccount procedure, to add the Database Mail account, which created in step 2, to the Database Mail profile, which created in step 3.

EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
@profile_name = 'XXXXXXXX', –-Profile Name on SMTP Server(User Defined)
@account_name = 'Admin', Account Name on SMTP (User Defined)
@sequence_number = 1


Step5: Use the sysmail_add_principalprofile procedure to grant the Database Mail profile access to the msdb public database role and to make the profile the default Database Mail profile..

EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
@profile_name = 'XXXXXXXX',
@principal_name = 'public',
@is_default = 1 ;


Step6: Now send a test email from SQL Server using sp_send_dbmail procedure..

DECLARE @Message AS VARCHAR(100)
SET @ Message ='Server :' + @@servername+ ' My First Database Email '
EXECUTE msdb.dbo.sp_send_dbmail
@recipients=' Shivaraj.gk@gmail.com', --Mail Recipient E-mail address (User Defined)
@subject = 'Hi, dear......Test Mail from Sql Server 2005',--Subject for the Mail
@body =@ Message, --Body of the Mail
@body_format = 'HTML'; --Body Format(HTML/Text)


Step7: You can check the configuration of the Database Mail profile and account using SQL Server Management Studio by right clicking Database Mail and clicking the Configuration..


Step8: The log related to Database Mail can be viewed by executing the statement below..


SELECT * FROM msdb.dbo.sysmail_event_log

Top Ten New and Exciting Features in ASP.NET 2.0

ASP.NET 1.0 was a revolutionary advance in developing Web Applications. With its fully complied, highly extensible Server-Side control model, it was one of the best applications of Microsoft’s .NET runtime. It solved many of the issues plaguing ASP developers, and kept the development-centric philosophy that made ASP such a huge hit amongst the web-client community.

But problems remained with the ASP.NET 1.0 release, not an entirely unexpected situation given it was, after all, a 1.0 product. Developers found themselves writing a lot more code than they thought was good, and it was more difficult than it should have been to keep presentation and business logic well-partitioned and separate.

With ASP.NET 2.0, the ASP.NET team has continued to lead the way in making developer’s daily lives more enjoyable. The main theme of ASP.NET 2.0 seems to be “write less code”. In this article, with homage to David Letterman, we will count down my top ten favorite features of this new runtime. (Feel free to imagine the top ten list being enthusiastically read by Bill Gates, but of course, in your imagination he will only be reading the topics themselves—I will be reading the actual explanations.)

With no further ado, we begin, as always, with:


10) Application-wide registration of custom controls.
One of my biggest complaints about custom controls (and this was true of both UserControls and custom controls from a custom assembly) was that you had to put a “<%@ Register %>” directive at the top of every .aspx page from which you wanted to declare an instance of the control.

One of the main purposes of custom controls was to be able to use them from multiple .aspx pages in one application. Since controls typically encapsulate elements like menus, site navigation etc., it seems counterintuitive to me that in order to reuse that code, you have to add something to each and every page. But in ASP.NET 1.0, there has to be one Register directive for each assembly/namespace combination and one for each UserControl. If you need to add a new custom control, you have to go into every page where you want to use it, and add it manually.

In ASP.NET 2.0, you can add the Register directives to the web.config.





tagPrefix="jonishappy"
namespace="JonIsHappyNamespace"/>





You might wonder, if I was so worked up over it in ASP.NET 1.0, why it is number 10 on my list and not number 1? To be fair, despite my ranting, it was annoying, but not really life-threatening. It usually wasn't too hard to find the problem in the first place, and a simple cut-and-paste operation usually fixed the problem in seconds.


9) Programmable Configuration.
This is really a .NET runtime improvement, but it is still a big win for ASP.NET. The web.config file contains all the configuration information for an ASP.NET application. In ASP.NET 1.0, in order to change something (like a database connection string in the AppSettings element) you have to open the web.config file in the text editor of your choice.

With the new version, you can go into the configuration programmatically (without having to resort to manipulating the XML directly) and change the settings of your ASP.NET applications. This makes building things like installers, administration modules, and pages much easier.


8) Web Part controls.
Even though the personalization craze of the web has somewhat died down in recent years, there still are plenty of situations in which you will need to expose customization of pages to your end users.

With Web Parts, the ASP.NET team has given us a way to do that without writing any additional code. The WebPartZone control is used to define an “area” of the page that can be customized. Each zone can be made up of multiple parts which can be a ContentWebPart control, a custom control, or a UserControl. Used in conjunction with the WebPartManager controls, you can give your end users the ability to change where the controls in their page are displayed.


7) Posting to other pages.
One programming paradigm that ASP.NET 1.0 developers had to get used to was that the HTML forms in ASP.NET 1.0 had to have their action attribute refer back to the page that created the rendered page.

This wasn’t so much a limitation on functionality, since with Response.Redirect or Server.Transfer, moving a user from one page to the other was just a matter of maintaining the page’s state for the second page to retrieve. But it was a nuisance just slightly above the @Register directive on the annoyance scale.

ASP.NET 2.0 gives controls that cause a post-back to the server the ability to change the action of the form in the HTML page, causing the page’s state and data to be posted directly to an ASP.NET page other than the one that created it.

In the ASP.NET where you are declaring the server-side controls you set the PostBackUrl property to the aspx page you’d like the form to submit to.

In the second page you can retrieve the data the user inputted into the HTML form rendered by the first page by accessing the PreviousPage property and finding each control you’d like to get data from.


6) SQL Cache Dependency.
The ASP.NET 1.0 HttpCache class was a great feature for maintaining application-level state. One of the coolest features was the ability to create a dependency between an object you placed into the cache with another object, a file, or a directory.

Since frequently the object that you put into the cache related back to a table in your database, probably the question I got asked the most often when lecturing on ASP.NET was whether an object put into the cache could be invalidated when the underlying table changed. The answer in ASP.NET 1.0 was no. The new answer is yes.

To make this work, you first have to configure the SQL Server instance using the aspnet_regsql.exe command line tool. Then create an instance of the SqlCacheDependency class and add that into the Cache object when adding your data to the Cache.


5) Master Pages.
Using implementation inheritance was a cornerstone of the ASP.NET 1.0 model. Each .aspx page was compiled into a .NET class, and System.Web.UI.Page was that class’ eventual base class.

One oft-used technique in ASP.NET 1.0 was to create a “master page class”. This class derived from Page and generally had all the common functionality that each and every .aspx page in an application needed to use. It was trivial to get ASP.NET to use this class as the base class for all classes generated from your .aspx files.

Since ASP.NET is a framework to create user interfaces, the downside of this “master base class” model was that any server-side controls that were added dynamically via this class wouldn’t appear in the .aspx file designer in Visual Studio .NET.

In ASP.NET 2.0 there is a new feature called Master Pages. Master Pages are essentially ASP.NET syntax in a file with the .master extension. A Master Page can be created and serves the same purpose as the “master base class”. There are two main differences with the Master Page model.

One, the .master pages are visually designable. Not only that, when a .aspx page uses a Master Page, the visual elements from the Master Page are displayed in the design view of the .aspx page – grayed out.

Two, the Master Page isn’t used as the base class for the .aspx file.


4) Visual Studio .NET project model.
One complaint that was heard around the world about ASP.NET 1.0 wasn’t really an ASP.NET problem, but a Visual Studio .NET (VS.NET) problem. Although ASP.NET supposed a number of different compilation and deployment models, VS.NET was fairly myopic in its view of how everyone should develop ASP.NET web applications. VS.NET’s model wasn’t wrong for every scenario, but it was wrong in enough instances to warrant a fairly bad rap when developing ASP.NET.

In ASP.NET 2.0, VS.NET (specifically VS.NET 2005) is much more flexible. It is flexible in terms of what part of an ASP.NET application may be open in the IDE at one time (no more solution files). VS.NET 2005 allows you to use a “codebehind” file or not, it is up to you, where VS.NET 2002/2003 both strictly enforced the “codebehind” file model.


3) Visual Studio .NET /ASP.NET compilation model.
In close connection with item number 4, VS.NET 2005 also frees the intrepid developer to compile at will. In fact, late compilation is the norm with 2005, which again is the opposite of the 2002/2003 model.

Part of this new lax view towards compilation goes hand in hand with new features built into ASP.NET 2.0. ASP.NET 2.0 takes advantage of the new feature built into C# and the CLR itself which allows a class to be defined in multiple files. Essentially, instead of “codebehind”, we now have “codebeside”, in which the class created from the .aspx file gets compiled into the same class that can exist in another file. This straightens out some of the weird object-oriented weirdness that sometimes ensued because of ASP.NET 1.0’s derived (.aspx ) base class (“codebehind”) model.

Also with ASP.NET 2.0 there is a command line compiler (aspnet_compile) that allows you to precompile a whole ASP.NET application. This feature is also exposed with a specialized handler which can be found at the precompile.axd endpoint in your application.


2) Provider model.
When the ASP.NET team looked at the code being written in the real world, they saw many chunks of code they felt they could build into the runtime itself. Many of these chunks need some data to back up the UI. Of course the ASP.NET team couldn’t choose a data source for every application, nor should they. So they used a layer of indirection.

This layer is known as a provider. A provider sits between the UI piece (the ASP.NET server-side control) and the data (which could be an ADO.NET data source, an XML file, or something else). The provider generally derives from a specific base class and that base class has methods that the UI piece can call to get the data necessary to render itself. ASP.NET 2.0 ships with providers for the most common types of data. If you have a different data source, you are free to build your own provider.

One standout example is membership. For membership, ASP.NET 2.0 ships a provider for Access and SQL Server, and a set of controls that allow logins, account creation, account editing, password reminders, etc. Building a gated web site with these new controls and a provider is really a snap. Expect to see more of this functionality unfold over time.


1) Declarative Databinding.
In ASP.NET 1.0, Databinding was one of the top features. Freeing developers from looping over rows of data and concatenating strings to generate HTML by allowing a control to just take a data object and run with it, with the rendered HTML being created based upon properties set on the control, was a genius idea. The only slight problem was that in order to make Databinding work, we still had to write code.

In ASP.NET 2.0, they introduce the concept of Declarative Databinding, which essentially allows you to declare the properties you want on your data source with the same declarative model you use to declare the server-side controls themselves. Datasource objects are created in the same way as server-side controls, by dragging and dropping them from the toolbox, or by adding the declaration to the .aspx file. Once configured, a datasource can be bound to a data-bound control.

Clearly, there are a lot more than just 10 new features in the ASP.NET 2.0 release; we could easily have turned this into a Top Twenty, Top Fifty or even Top One Hundred list, had we wanted. ASP.NET marks a huge new set of functionality, driven by customer demands and requests, and your Top Ten list will likely differ from my own, depending on your experience and history with ASP.NET. But in the meantime, while you're building your own list, try starting with these 10—I think you'll like these new features just as much as I do.

The following are the some limitations of Sql server table.

The maximum number of columns per base table is 1024.

The maximum number of columns per index is 16.

The maximum number of columns per SELECT statement is 4096.

The maximum number of foreign key table references per table is 253.

The maximum number of parameters per stored procedure is 1024.

The maximum number of characters allowed for a table name is 128.

The maximum number of characters allowed for a column name 128.

Difference Between Clustered and Non-Clustered Index Data Structures

Part I: Non-Clustered Index

Creating a Table
To better explain SQL Server non-clustered indexes; let’s start by creating a new table and populating it with some sample data using the following scripts. I assume you have a database you can use for this. If not, you will want to create one for these examples.

Create Table DummyTable1
(
EmpId Int,
EmpName Varchar(8000)
)

When you first create a new table, there is no index created by default. In technical terms, a table without an index is called a “heap”. We can confirm the fact that this new table doesn’t have an index by taking a look at the sysindexes system table, which contains one for this table with an of indid = 0. The sysindexes table, which exists in every database, tracks table and index information. “Indid” refers to Index ID, and is used to identify indexes. An indid of 0 means that a table does not have an index, and is stored by SQL Server as a heap.

Now let’s add a few records in this table using this script:

Insert Into DummyTable1 Values (4, Replicate ('d',2000))
GO

Insert Into DummyTable1 Values (6, Replicate ('f',2000))
GO

Insert Into DummyTable1 Values (1, Replicate ('a',2000))
GO

Insert Into DummyTable1 Values (3, Replicate ('c',2000))
GO

Now, let’s view the contests of the table by executing the following command in Query Analyzer for our new table.

Select EmpID From DummyTable1
GO

Empid

4

6

1

3


As you would expect, the data we inserted earlier has been displayed. Note that the order of the results is in the same order that I inserted them in, which is in no order at all.

Now, let’s execute the following commands to display the actual page information for the table we created and is now stored in SQL Server.

dbcc ind(dbid, tabid, -1) – This is an undocumented command.

DBCC TRACEON (3604)
GO

Declare @DBID Int, @TableID Int
Select @DBID = db_id(), @TableID = object_id('DummyTable1')

DBCC ind(@DBID, @TableID, -1)
GO

This script will display many columns, but we are only interested in three of them, as shown below.

PagePID
IndexID
PageType

26408
0
10

26255
0
1

26409
0
1


Here’s what the information displayed means:

PagePID is the physical page numbers used to store the table. In this case, three pages are currently used to store the data.

IndexID is the type of index,

Where:

0 – Datapage

1 – Clustered Index

2 – Greater and equal to 2 is an Index page (Non-Clustered Index and ordinary index),

PageType tells you what kind of data is stored in each database,

Where:

10 – IAM (Index Allocation MAP)

1 – Datapage

2 – Index page

Now, let us execute DBCC PAGE command. This is an undocumented command.

DBCC page(dbid, fileno, pageno, option)

Where:

dbid = database id.

Fileno = fileno of the page. Usually it will be 1, unless we use more than one file for a database.

Pageno = we can take the output of the dbcc ind page no.

Option = it can be 0, 1, 2, 3. I use 3 to get a display of the data. You can try yourself for the other options.

Run this script to execute the command:

DBCC TRACEON (3604)
GO

DBCC page(@DBID, 1, 26408, 3)
GO

The output will be page allocation details.

DBCC TRACEON (3604)
GO

dbcc page(@DBID, 1, 26255, 3)
GO

For More Inoframtion View this web page
http://www.sql-server-performance.com/articles/per/index_data_structures_p1.aspx