This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Wednesday, July 3, 2013

Stored Procedure (SP)

What is a Stored Procedure (SP)

The stored procedure is a set of PL/Sql statements written inside a named block. We use stored procedures in Sql Server to perform the very basic operations on database tables.

Advantages


Stored Procedures are very much useful in multidevelopment environment. As they serve the developers or applications from single point.
They are precompiled and the execution of the stored procedures is very fast when compared to sql queries
They sit inside the database and executes from it. The changes made in one place are visible to everybody whoever is accessing the stored procedures.

Stored Procedure Syntax


CREATE PROCEDURE <Procedure_Name, sysname, ProcedureName>
-- Add the parameters for the stored procedure here
<@Param1, sysname, @p1> <Datatype_For_Param1, , int> = <Default_Value_For_Param1, , 0>,
<@Param2, sysname, @p2> <Datatype_For_Param2, , int> = <Default_Value_For_Param2, , 0>
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

    -- Insert statements for procedure here
SELECT <@Param1, sysname, @p1>, <@Param2, sysname, @p2>
END
GO

The syntax is very clear starts with the command CREATE PROCEDURE followed by procedure name and the list of parameters  that can be passed to it with datatypes and default values.  The parameters declared here must be passed from the context from where the procedure is getting executed. If nothing passed  for a parameter and any default value assigned to it then the default value will be taken and the procedure executes. If no default value assigned then it will through an error like 'Value does not supplied for <Parameter_1>'

After the parameter declaration we will begin the actual body of the procedure and start writing the business logic and Sql queries for the processing.

Stored Procedures Best Practices

  So far we saw the syntax and parameter declaration for the stored procedure. Now this is the time to see how we can write stored procedures for a particular table. What are the best practices to do it.

  For any database table the primary thing or primary operations that we can implement are CRUD operations.

C - Create / Insert
R - Read / Select
U - Update / Edit
D - Delete / Remove

These are the basic operations, that every database programmer should implement for every table. The industry standards or the best practices followed by developers are as follows..

Before getting into the practices first create a table with the following statement on you database.

Create Table Script

CREATE TABLE [dbo].[Customer](
[CustomerID] [int] IDENTITY(1,1) NOT NULL,
[CustomerName] [varchar](50) NULL,
[YTDOrders] [int] NULL,
[YTDSales] [int] NULL,
 CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED
(
[CustomerID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

The table is created as CustomerID as integer, identity column and primary key. So what ever operations we perform the primary key is important to perform different kinds of operations like update, select and delete.

Stored Procedure for UPSERT

  Don't get frightened by this new word UPSERT, this is name used by DB programmers for stored procedures which performs both insert + update. So the very first step we should consider for our table is to write a procedure which performs both insert and update operations as below.

Procedure Script

CREATE PROCEDURE Customer_Upsert
@CustomerID int=null,
@CustomerName nvarchar(40)=null,
@YTDOrders int=null,
@YTDSales int=null
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

   if(@CustomerID is null)
INSERT INTO Customer(CustomerName,YTDOrders, YTDSales) Values(@CustomerName,@YTDOrders,@YTDSales)
   else
UPDATE Customer SET
CustomerName=coalesce(@CustomerName, CustomerName),
YTDOrders=coalesce(@YTDOrders,YTDOrders),
YTDSales=coalesce(@YTDSales,YTDSales)
WHERE CustomerID=@CustomerID
END
GO

Here we are passing all the columns values as parameters and we are assigning them with their respective default values. The advantage of assigning default values is when application developers working with this procedure and they forgot to pass few parameter values then it should break. And the default value assignment is very much useful when we are performing some search kind of filtering and on update operations.

Here we are checking whether the @CustomerID is passed or not? for new records as they wont have any primary column value it will be passed empty and our stored procedure will identifies it as new records and the insertion statement executes.

Try with this sample statement:

  EXEC Customer_Upsert @CustomerName='Insert SP',@YTDOrders='13',@YTDSales='4'

And now execute the select statement to see the records in the table

Result after Upsert Stored Procedure Performed Insert


If the @CustomerID is passed our Stored Procedure will identify as it is already exists and executes the Update statement accordingly.

Here the interesting point we should see is COALESCE, this is function is very very useful while updating. Suppose consider in some scenario I have updated only few column values for a customer. I want to update the sales of a customer then I will pass only the new value for sales what about other column values if I dont pass their values if I do not use COALESCE i will end up in some permutations and combinations as I need to write conditions like if only customer name passed or customer name plus sales like this. Now it COALESCE solves my problem and provide simple single line statement to finish my job.

What it will do is. It checks whether the passed value is null or not. If it is null it will assign the old value to it
other wise the new value.

Try with this simple Sql Statement

                  EXEC Customer_Upsert @CustomerID=1,@YTDSales='10'  

Result after upsert stored procedure executes update
Now see the result and compare with the old result select after insert.

This is how we one should write Upsert stored procedure, which will provide two kinds functionality to insert and update.

Stored Procedure For Delete

This is very simple procedure to do, and requires only primary key or any combination of columns. But the delete is of 2 kinds.

Procedure Script


USE [SampleDAC]
GO

/****** Object:  StoredProcedure [dbo].[Customer_Delete]    Script Date: 01/08/2013 23:28:39 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[Customer_Delete]
@CustomerID int,
@DeletePermanent bit
AS
BEGIN

SET NOCOUNT ON;

IF @DeletePermanent = 1
DELETE FROM Customer WHERE CustomerID=@CustomerID
ELSE
UPDATE Customer SET IsActive=0 where CustomerID=@CustomerID

END

GO


1.Permanent Delete: Here we delete entire row for a passed primary key. The above stored procedure has the section IF to deal with this functionality

          IF @DeletePermanent = 1
DELETE FROM Customer WHERE CustomerID=@CustomerID

Example:

     EXEC dbo.Customer_Delete 3,1
     SELECT * FROM Customer
1 Insert SP 0 10 1
2 update sp 20 23 0
4 select sp 20 23 1
5 select sp1 21 24 1

     This shows the results it deleted the records number 3 permanently from the database

2. Soft Delete: Here we will make a row as disabled by means of maintaining a bit column for that table. If the bit value is 1 it is active other wise it is disabled.

 Now to try this add a new column of type bit and name it as IsActive to customers table

          ALTER TABLE Customer ADD IsActive BIT

The above stored procedure has the section ELSE which deals with the soft delete means it will update the records flag as "0" to indicate that this records is in not use or disabled.


ELSE
UPDATE Customer SET IsActive=0 where CustomerID=@CustomerID

    Example :

                      EXEC dbo.Customer_Delete 2,0
                      SELECT * FROM Customer


1 Insert SP 0 10 1
2 update sp 20 23 0
4 select sp 20 23 1
5 select sp1 21 24 1

  If you see the above results it is clear that row number 2 IsActive flag has been set to 0 means the record is no more in use or it is disabled our queries should be written to check this flag

Stored Procedure For Reader

 This is the final and last part plays very important role in the data accessing, fetching or reading part of any database table.

Procedure Script

CREATE PROCEDURE [dbo].[Customer_Reader]
@CustomerID int=null,
@CustomerName varchar(50)=null,
@IsActive bit = null
AS
BEGIN

SET NOCOUNT ON;

SELECT * FROM Customer
WHERE
(CustomerID=@CustomerID OR @CustomerID IS NULL)
AND (CustomerName=@CustomerName OR @CustomerName IS NULL)
AND (IsActive =@IsActive OR @IsActive IS NULL)

END

GO

This is simple script and we are declaring all the parameters as optional means you can pass combination of these or none to the procedure. If you dont pass any parameter it will return all the records from table. Or if you pass any combination of these parameters means you can pass any one, two or three of them according to your paramter filteration the result will come.

How It Works

This is pretty simple as all we know truth table for OR & AND as they are like below. We can easily identify the results of it

Just check if I dont pass any parameter to this procedure what will happen

CustomerID=@CustomerID i.e. False
@CustomerID IS NUll i.e. True
False or True i.e. True

Like this others means all filters returns true and And operation returns true. and it returns all the records from the table

Truth table for And Operation
Truth table for OR Operation


Like wise which ever parameter you pass for that if the value is true and the others by default they return true because they are null you will get exact result.

This is how our most of the search operations on websites are implemented.

Example :

 EXEC dbo.Customer_Reader


1 Insert SP 0 10 1
2 update sp 20 23 0
4 select sp 20 23 1
5 select sp1 21 24 1

EXEC dbo.Customer_Reader @CustomerID=1


1 Insert SP 0 10 1

EXEC dbo.Customer_Reader @IsActive=1


1 Insert SP 0 10 1
4 select sp 20 23 1
5 select sp1 21 24 1

This is how we should practice with the stored procedures while writing. I hope this tutorial helps you.

Simple Survey Application

Introduction:

         The companies which are offering variety of services to the customers, they need to get the response from the customers in many forms. By analyzing these responses companies will have an overview of their services and performance.

         The surveys or polls are very much important in different situation and organizations. for examples, consider a company is selling different products in the market. If they want to know the product usage and end user satisfaction they will conduct a simple survey among the users after collecting most of the public responses, they start analyzing these response in different angles like,
  1. What is usage percentage of this product among the people.
  2. How often people are purchasing this product
  3. Public satisfaction index and etc.

All these will be helpful in 

  • Promoting their business to next level.
  • And to analyze the market capture in nearest future. 
  • and to increase the production according to market needs

Solution:

        We have different websites which are providing simple prepare your question and answer sets and publish or share you survey link to the targeted groups, networks or individuals.

        We can have our own solution embed in our regular applications which will be opened for a duration for the organization people to fill.

        And finally for common people to share their surveys or polls we have social networking sites offering with limited features.

Problem Statement

      We need to develop a simple application where administrators can prepare a questionnaire and prepare a simple survey and share it to the people who ever registered on our website.

       Once the survey filled by end users, the web site administrator or who ever is authorized can be analyze the survey results, feedback in any form like graphical or textual.

This Example has the following requirements:

  Consider we have a requirement to conduct survey on customers travel experience for the tickets booked from an online reservation system. Which providing services to book tickets from different travel agencies.

High Level Design:


Survey application use case

Actors:

Administrator: The person who prepares the surveys and share it with the registered users via mail.
Manager: The person who analyzes and prepares reports on the filled surveys
User: Is the actual and user who fills the survey forms after getting them via mail.

Actions: 

Register: The user registers to the website initially
Create Survey: The administrator creates the survey
Share Survey: Once the survey creates Admin shares this survey with end users
Fill Survey: End user fills and sends the response.
Analyze Survyes: once the survey responses start getting Manage can start analyzing them on different parameters

Class Diagrams:




DB Schema:



simple survey app schema

  The Schema very much simple and says the relation between all the entities in the application.
So far we are done with High Level Design, DB Design and Class diagrams. Now we see how the actual application development developed step by step.

Create Database

Create a new database with the  name SurveyApp as shown in the figure

sql server database screen

Create new tables with the following script on this database


USE [SurveyApp]
GO
/****** Object:  Table [dbo].[Roles]    Script Date: 09/12/2012 15:46:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Roles](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](200) NOT NULL,
 CONSTRAINT [PK_Roles] PRIMARY KEY CLUSTERED 
(
[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Questions]    Script Date: 09/12/2012 15:46:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Questions](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Text] [varchar](200) NOT NULL,
[QuestionType] [varchar](200) NOT NULL,
[Options] [varchar](2000) NOT NULL,
 CONSTRAINT [PK_Questions] PRIMARY KEY CLUSTERED 
(
[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Users]    Script Date: 09/12/2012 15:46:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Users](
[ID] [int] IDENTITY(1,1) NOT NULL,
[FirstName] [varchar](200) NOT NULL,
[LastName] [varchar](200) NULL,
[UserName] [varchar](200) NOT NULL,
[Password] [varchar](200) NOT NULL,
[Role] [int] NOT NULL,
 CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED 
(
[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Surveys]    Script Date: 09/12/2012 15:46:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Surveys](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Title] [varchar](200) NULL,
[Description] [varchar](200) NOT NULL,
[CreatedOn] [datetime] NOT NULL,
[ExpiresOn] [datetime] NULL,
[CreatedBy] [int] NOT NULL,
[Publish] [bit] NOT NULL,
 CONSTRAINT [PK_Surveys] PRIMARY KEY CLUSTERED 
(
[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[SurveyResponse]    Script Date: 09/12/2012 15:46:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[SurveyResponse](
[ID] [int] NOT NULL,
[SurveyID] [int] NOT NULL,
[QuestionID] [int] NOT NULL,
[Response] [varchar](200) NOT NULL,
[FilledBy] [int] NOT NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Survey_Questions]    Script Date: 09/12/2012 15:46:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Survey_Questions](
[ID] [int] NOT NULL,
[SurveyID] [int] NOT NULL,
[QuestionID] [int] NOT NULL,
[OrderId] [int] NULL
) ON [PRIMARY]
GO
/****** Object:  ForeignKey [FK_Survey_Questions_Questions]    Script Date: 09/12/2012 15:46:11 ******/
ALTER TABLE [dbo].[Survey_Questions]  WITH CHECK ADD  CONSTRAINT [FK_Survey_Questions_Questions] FOREIGN KEY([QuestionID])
REFERENCES [dbo].[Questions] ([ID])
GO
ALTER TABLE [dbo].[Survey_Questions] CHECK CONSTRAINT [FK_Survey_Questions_Questions]
GO
/****** Object:  ForeignKey [FK_Survey_Questions_Surveys]    Script Date: 09/12/2012 15:46:11 ******/
ALTER TABLE [dbo].[Survey_Questions]  WITH CHECK ADD  CONSTRAINT [FK_Survey_Questions_Surveys] FOREIGN KEY([SurveyID])
REFERENCES [dbo].[Surveys] ([ID])
GO
ALTER TABLE [dbo].[Survey_Questions] CHECK CONSTRAINT [FK_Survey_Questions_Surveys]
GO
/****** Object:  ForeignKey [FK_SurveyResponse_Questions]    Script Date: 09/12/2012 15:46:11 ******/
ALTER TABLE [dbo].[SurveyResponse]  WITH CHECK ADD  CONSTRAINT [FK_SurveyResponse_Questions] FOREIGN KEY([QuestionID])
REFERENCES [dbo].[Questions] ([ID])
GO
ALTER TABLE [dbo].[SurveyResponse] CHECK CONSTRAINT [FK_SurveyResponse_Questions]
GO
/****** Object:  ForeignKey [FK_SurveyResponse_Surveys]    Script Date: 09/12/2012 15:46:11 ******/
ALTER TABLE [dbo].[SurveyResponse]  WITH CHECK ADD  CONSTRAINT [FK_SurveyResponse_Surveys] FOREIGN KEY([SurveyID])
REFERENCES [dbo].[Surveys] ([ID])
GO
ALTER TABLE [dbo].[SurveyResponse] CHECK CONSTRAINT [FK_SurveyResponse_Surveys]
GO
/****** Object:  ForeignKey [FK_SurveyResponse_Users]    Script Date: 09/12/2012 15:46:11 ******/
ALTER TABLE [dbo].[SurveyResponse]  WITH CHECK ADD  CONSTRAINT [FK_SurveyResponse_Users] FOREIGN KEY([FilledBy])
REFERENCES [dbo].[Users] ([ID])
GO
ALTER TABLE [dbo].[SurveyResponse] CHECK CONSTRAINT [FK_SurveyResponse_Users]
GO
/****** Object:  ForeignKey [FK_Surveys_Users]    Script Date: 09/12/2012 15:46:11 ******/
ALTER TABLE [dbo].[Surveys]  WITH CHECK ADD  CONSTRAINT [FK_Surveys_Users] FOREIGN KEY([CreatedBy])
REFERENCES [dbo].[Users] ([ID])
GO
ALTER TABLE [dbo].[Surveys] CHECK CONSTRAINT [FK_Surveys_Users]
GO
/****** Object:  ForeignKey [FK_Users_Roles]    Script Date: 09/12/2012 15:46:11 ******/
ALTER TABLE [dbo].[Users]  WITH CHECK ADD  CONSTRAINT [FK_Users_Roles] FOREIGN KEY([Role])
REFERENCES [dbo].[Roles] ([ID])
GO
ALTER TABLE [dbo].[Users] CHECK CONSTRAINT [FK_Users_Roles]
GO

Create Project

  1. On Visual studio select new project 
  2. Select asp.net web application template
  3. Name the project as SimpleSurvey

New Project

Remove all default created folder as shown in the below figure

Survey Project
Add new form to the project with the name SurveyForm.aspx
New Survey Form
Add a new class with name SurveysManager.cs
Survey Manager Form
Add an enumeration to the application so that we can easily categorize questions
Add the following enumeration to SurveysManager.cs
    public enum QuestionTypes
    {
        SingleLineTextBox, // will render a textbox 
        MultiLineTextBox, // will render a text area
        YesOrNo, //will render a checkbox
        SingleSelect, //will render a dropdownlist
        MultiSelect //will render a listbox
    }

Entity Framework for DB Interface

 Here we are going to use EF for DB related actions. Just add a new file with the name SurveyAppContext.edmx file as shown below.

Add new item of ADO.NET Entity Model from visual studio data templates.

Survey Application

Choose select Generate from database model to proceed

Data Model

 Choose a connection string and proceed

Database Connection String

Select the tables required for db activities and finish

Database tables

Finally the Entity Framework will generate the model in visual studio as below and the it generates necessary methods to perform CRUD operations on entities. This you can check on below images.

Survey Application Model
Model
Survey Application Project Hieraurchy
Create A new form to Manage Questions That should like as below.

Manage Questions
Create a new form to manage surveys that should like as below
Manage Survey
We are done with creating the Manage Questions and Manage Surveys screens. Now we are half done with the requirement. These two will provide us the way to add few questions and surveys.

We take a simple example of User feedback form for product.

  The feedback should consists of the following Question.
  1. First Name
  2. Last Name
  3. User Email ID
  4. Mobile Number (Optional)
  5. Rating (1 to 5)
  6. Comments
And the survey title should be <XXXX> Feedback Form
Add all the questions from the Manage Questions Screen.
Survey Application
Add feedback survey from Manage Survey Screen.
Survey Application
As shown in the above step add all the questions and survey to the database. 

Feedback Form Rendering

The actual part of the application now we will discuss. 
Step - I Fetch the respective Survey definition from the database:
   Our render page will be like this and will list number of surveys added already. Select to render the sample feedback form.
Feedback Form
Finally once you selected the survey you on drop down list. It will post back and render the page with questions and respective fields as shown in the figure below.
Survey Form
The basic code format is here how to render the page with respective controls.

 private void PopulateSurvey()
        {
            List<Question> questions = (from p in context.Questions
                                        join q in context.SurveyQuestions on p.ID equals q.QuestionID
                                        where q.SurveyID == surveyid
                                        select p).ToList();
            Table tbl = new Table();
            tbl.Width = Unit.Percentage(100);
            TableRow tr;
            TableCell tc;
            TextBox txt;
            CheckBox cbk;
            DropDownList ddl;

            foreach (Question q in questions)
            {
                tr = new TableRow();
                tc = new TableCell();
                tc.Width = Unit.Percentage(25);
                tc.Text = q.Text;
                tc.Attributes.Add("id", q.ID.ToString());
                tr.Cells.Add(tc);
                tc = new TableCell();

                if (q.QuestionType.ToLower() == "singlelinetextbox")
                {
                    txt = new TextBox();
                    txt.ID = "txt_" + q.ID;
                    txt.Width = Unit.Percentage(40);
                    tc.Controls.Add(txt);
                }

                if (q.QuestionType.ToLower() == "multilinetextbox")
                {
                    txt = new TextBox();
                    txt.ID = "txt_" + q.ID;
                    txt.TextMode = TextBoxMode.MultiLine;
                    txt.Width = Unit.Percentage(40);
                    tc.Controls.Add(txt);
                }

                if (q.QuestionType.ToLower() == "singleselect")
                {
                    ddl = new DropDownList();
                    ddl.ID = "ddl_" + q.ID;
                    ddl.Width = Unit.Percentage(41);
                    if (!string.IsNullOrEmpty(q.Options))
                    {
                        string[] values = q.Options.Split(',');
                        foreach (string v in values)
                            ddl.Items.Add(v.Trim());
                    }
                    tc.Controls.Add(ddl);
                }
                tc.Width = Unit.Percentage(80);
                tr.Cells.Add(tc);
                tbl.Rows.Add(tr);
            }
            pnlSurvey.Controls.Add(tbl);
        }
Below is the code to get response from the dynamic controls, after the submit button is clicked.
 private List<Survey_Response> GetSurveyReponse()
        {
            List<Survey_Response> response = new List<Survey_Response>();
            foreach (Control ctr in pnlSurvey.Controls)
            {
                if (ctr is Table)
                {
                    Table tbl = ctr as Table;
                    foreach (TableRow tr in tbl.Rows)
                    {
                        Survey_Response sres = new Survey_Response();
                        sres.FilledBy = 2;
                        sres.SurveyID = surveyid;
                        sres.QuestionID = Convert.ToInt32(tr.Cells[0].Attributes["ID"]);
                        TableCell tc = tr.Cells[1];
                        foreach (Control ctrc in tc.Controls)
                        {
                            if (ctrc is TextBox)
                            {
                                sres.Response = (ctrc as TextBox).Text.Trim();
                            }
                            else if (ctrc is DropDownList)
                            {
                                sres.Response = (ctrc as DropDownList).SelectedValue;
                            }
                            else if (ctrc is CheckBox)
                            {
                                sres.Response = (ctrc as CheckBox).Checked.ToString();
                            }
                        }
                        response.Add(sres);
                    }

                }
            }
            return response;
        }

This is simple application and can be extended to get more features and can include more functionality to get more live functionality. Working code can be downloaded here


bio metric log text file import and validate in attendance management system


Bio metric log text  file Upload and export   to excel sheets  in vb.net   project in attendance system


                                                               Browse Bio Metric Log file

Import bio metric log file

Validate Bio Metric log file 



Click Here To Download Bio metric log txt  file  to excel sheets 

Tuesday, July 2, 2013

Converting MS SQL Database to MySQL



                         If you want to Convert your sql server database tables, stroed procs, functions etc 

to Mysql ,you can use this tool . Here is the URL



http://www.ispirer.com/products/sql-server-to-mysql-migration



You can either use free evaluation or can purchase. You need to register before downloading the tool.