Search Binary Spectrum
Home | Resources | Sitemap | Support Binaryspectrum develops EMR, EHR, Practice Management, e-prescription, e-Commerce, CRM and SCM systems using .Net, J2EE, Oracle, Bluetooth and Piconet platforms
Binaryspectrum uses .Net, J2EE, Oracle, Bluetooth and Piconet platforms
Binaryspectrum Binaryspectrum develops EMR, EHR, Practice Management, e-prescription, e-Commerce, CRM and SCM systems using .Net, J2EE, Oracle, Bluetooth and Piconet platforms Binaryspectrum develops EMR, EHR, Practice Management, e-prescription, e-Commerce, CRM and SCM systems using .Net, J2EE, Oracle, Bluetooth and Piconet platforms Binaryspectrum develops EMR, EHR, Practice Management, e-prescription, e-Commerce, CRM and SCM systems using .Net, J2EE, Oracle, Bluetooth and Piconet platforms Binaryspectrum develops EMR, EHR, Practice Management, e-prescription, e-Commerce, CRM and SCM systems using .Net, J2EE, Oracle, Bluetooth and Piconet platforms Binaryspectrum
Binaryspectrum develops Practice Management software
Binary spectrum developsoftware compliant with HIPAA Standards
Binaryspectrum's CRM and SCM systems
Binaryspectrum develops EMR, EHR, Practice Management, e-prescription, e-Commerce, CRM and SCM systems using .Net, J2EE, Oracle, Bluetooth and Piconet platforms with Microsoft certified professionals
 Contact Us

September 08, 2009

Using SMO for Dynamically Creating Stored Procedure and Database Tables in c#.net

-          Tauseef.M

 

According to me “Giving a deadly desired storm to your brain yields in an ‘invention ‘. 


What is SMO??

Server Management Object (SMO) is Microsoft® .NET Framework library of objects that let you manage one or more database servers. SMO can be used to examine a database’s objects and to perform a variety of administrative tasks like backing up and restoring databases, and issuing Data Definition Language (DDL) commands. Using SQL SMO you can also connect to SQL Server, iterate through a collection of database objects and perform a variety of tasks against them.
Let me demonstrate the use of SMO for dynamically creating of Stored Procedures and Database Tables.

For start up, let us first reference the appropriate assemblies that use SMO.


The two main DLLs you must reference are:

  • Microsoft.SqlServer.Smo.dll
  • Microsoft.SqlServer.ConnectionInfo.dll

You will also need the following assembly for creating indexes for primary key:
Microsoft.SqlServer.SqlEnum.dll

After adding the above assemblies let’s begin Dynamic Creation of Stored Procedure and Database Tables.

Dynamically Creating Database Tables

Below is a simple Code that creates the database table known as tblEmployee in my personal database Employee with a primary key and identity on the ID column.   

 //Establish Conection
            SqlConnection conn = new SqlConnection
("Server=<servername>;DATABASE=<databasename>;uid=<userid>;pwd=<pwd>");
       //Create Server instance
            Server server = new Server(new ServerConnection(conn));
       //Create Database Instance from existing databases
            Database database = server.Databases["Employee"];
       //Create Table
            Microsoft.SqlServer.Management.Smo.Table table = new
    Microsoft.SqlServer.Management.Smo.Table(database, "tblEmployee");
      
       //Create Column "ID" as Primary key
            Column IDcolumn = new Column(table, "ID");
            IDcolumn.DataType = DataType.Int; //Specify the datatype
            IDcolumn.Nullable = false;        //Allow Nulls=False
            IDcolumn.Identity = true;         //Set Identity=True
            IDcolumn.IdentitySeed = 1;        //Set Identity to start from 0
            IDcolumn.IdentityIncrement = 1; //Increment identity value by 1                                                  
          
      //Create Column "Title"
            Column TitleColumn = new Column(table, "Title");
            TitleColumn.DataType = DataType.VarChar(50);
            TitleColumn.Nullable=true;
        
      //Add Columns to the "table"
            table.Columns.Add(IDcolumn);
            table.Columns.Add(TitleColumn);
      //Create index  for primary key column "ID"
            Index prIndex = new Index(table, "PK_ID");
      //specify as primary key
            prIndex.IndexKeyType = IndexKeyType.DriPrimaryKey;           
     //Assign the column "ID" to the created Index
            prIndex.IndexedColumns.Add(new IndexedColumn(prIndex,"ID"));
     //Add the new Index to the table
            table.Indexes.Add(prIndex);
     //PHYSICALLY create the table in the database
            table.Create();

            Response.Write("Table Created Sucessfully...");


Dynamically Creating Stored  Procedures
Below is a simple Code that creates the Stored Procedure known as “
dsp_created “in my personal database Employee with @cityid being the input variable.        

 

//Establish Conection
            SqlConnection conn = new SqlConnection
("Server=<servername>;DATABASE=<databasename>;uid=<userid>;pwd=<pwd>");
       //Create Server instance
        Server server = new Server(new ServerConnection(db));
        //Select the database where stored procedure needs to be added
        Database dsb = server.Databases["Employee"];

        //Create a Stored Procedure named "dsp_created" in "Employee"
        StoredProcedure sp = new StoredProcedure(dsb, "dsp_created");
        sp.TextMode = false;        //set TextMode as false
        sp.AnsiNullsStatus = false; //set AnsiNullsStatus as false
        sp.QuotedIdentifierStatus = false;

        //Add an input parameter "@cityid" to the Stored Procedure
     StoredProcedureParameter idparam = new   
           StoredProcedureParameter(sp, "@cityid", DataType.Int);
        sp.Parameters.Add(idparam);
        //The Sql Statement
        sp.TextBody = "Select *from tblCity where Citycode= @cityid";
        //PHYSICALLY create Stored Procedure
        sp.Create();

        Response.Write("Stored Procedure Created Sucessfully....");

Dynamically deletion of stored procedure is also very simple, which will be explained later.    

(The author, Tauseef.M, is a Software Engineer at Binary Spectrum.)

 

August 03, 2009

Create an Ongoing task in MS Project

- Jayanth Raj

 

We can create an ongoing task in MS Project by creating a “Hammock Task”. Hammock task duration changes automatically when the project finish date is changed.


Steps for creating a Hammock Task:
1.     Click on Project start date cell, the start date cell will be highlighted.
2.     On the edit menu, click copy (cell)
3.     Click on the ‘ongoing task’ start date, the start date cell will be highlighted.
4.     On edit menu, click ‘Paste Special’ and click ‘Paste Link’.
5.     Click on Project end date cell, the end date cell will be highlighted.
6.     On the edit menu, click copy (cell)
7.     Click on the ‘ongoing task’ end date, the end date cell will be highlighted.
8.     On edit menu, click ‘Paste Special’ and click ‘Paste Link’.


For more details see the below link:
http://support.microsoft.com/kb/141733 (How to build a Hammock Task).


(The author, Jayanth Raj is a Software Engineer at Binary Spectrum).

 

June 20, 2009

Excel to MYSQL: Here's another technique

- Anjana. M

I had to upload pin codes in excel to database. After procrastinating on net for considerable time, I decided to find a quick solution... :) Though I am aware of available excel api’s, I dint want to spend time in reading api docs for breaking a thin twig. This method can be followed if you want to export a single column from excel to a table.  

Steps:
  1. So i copied the pin code column  from the excel and pasted on to a notepad
  2. Save the file as ok.txt
  3. then I wrote program that will read a the file line by line and a simple string operation
  4. The program will generate a Sql script and will also execute the script and will insert the data into database.

    "*********Sample output*********"

insert into tblpincode_zone(pincodes,zone)values(834001,9);

insert into tblpincode_zone(pincodes,zone)values(834002,9);

***********************************

package beans;  

import java.io.*;

import java.sql.*;

class FileRead

   public static void main(String args[])

  { 

       try{

           Connection con=null; 

        Statement pst=null;

       String str=""; 

       Class.forName("com.mysql.jdbc.Driver");

    con=DriverManager.getConnection("jdbc:mysql://192.169.70.45/application?user=root&password=root");         

    // Open the file that is the first

    // command line parameter 

    FileInputStream fstream = new FileInputStream("D:/ok.txt");

    // Get the object of DataInputStream 

    DataInputStream in = new DataInputStream(fstream);

        BufferedReader br = new BufferedReader(new InputStreamReader(in)); 

    String strLine;

    //Read File Line By Line 

    while ((strLine = br.readLine()) != null)   {

      pst=con.createStatement(); 

      // Print the content on the console

      System.out.println ("insert into tblpincode_zone(pincodes,zone)values("+strLine+",9);");      str="insert into tblpincode_zone(pincodes,zone)values("+strLine+",9);"; 

     pst.executeUpdate(str);

    } 

    //Close the input stream

    in.close(); 

    }catch (Exception e){//Catch exception if any

      System.err.println("Error: " + e.getMessage()); 

    }

  }

}

 

(The author, Anjana.M, is a Software Engineer at Binary Spectrum).

 

June 19, 2009

Ruby on Rails: Convensions over Configurations

- Jagadish. M

The interest of developer will always be towards learning new technologies. It’s secondary that whether in real-time you are going to use it in or not. One of the most popular and fastest growing technologies that I came across is Ruby on Rails (RoR).

Ruby on Rails was developed by David Heinemeier Hansson from his work on BaseCamp; a project management tool, which offers to-do lists, wiki-style web-based text documents, milestone management, file sharing, time tracking, and a messaging system.

Like many web frameworks, Rails uses the Model View Controller (MVC) architecture to organize applications.

Features of Ruby:
  • Each and Everything is Object: Even numbers in ruby are treated as object. Looking at the example, what output you can expect from this?

8.times {print “Guess what”} its prints Guess what 8 times.

  • Powerful blocks: Code blocks can be passed as parameter to method. Following example prints out all the elements in an array

    jArray.each{|element| print element}

  • Return is optional in Methods: In ruby return statement is optional in methods. The value of the last expression becomes the return value of that method. For example: 

    def testReturn n = 2 * 3 en

  • Parallel Assignment in Ruby: We can change the multiple variables in one assignment statement. Swapping of two variables is the good example for it.   n1 = 1

    n2 = 3

     n1, n2 = n2,n1

  • Everything in Ruby is open: Including the built-in classes, in ruby, additional methods can be added to the classes even at run-time also. For example: FixNum is the build in Data Type for all to which I added the method called old.                         
  • class Fixnum

    def old return self-1

    end

    end

    8.old  # prints 7

    (The author, Jagadish.M, is a Software Engineer at Binary Spectrum).

May 20, 2009

ATG: Enhancing ecommerce!

-Jagadish.M

Recently, while I visited few sites, I was caught by this very interesting tale of ATG. I came across their dynamic capabilities and thought of sharing it and creating awareness to all.


ATG Technologies:
In the line of ecommerce, ATG is the technology that is growing faster than any other technologies currently. ATG (Art Technology Group, Inc., NASDAQ: ARTG) develops software and delivers e-commerce and Web marketing solutions that many global brands utilize to empower their e-commerce Web sites. ATG's ecosystem of Complementary Software Providers extends the ATG Commerce suite with unique and innovative capabilities like dynamic imaging, ratings and reviews, and payment.


ATG Commerce Suite:
ATG Commerce Suite provides a solid, stable, yet highly flexible and agile foundation for the highest volume e-commerce sites. With its  dynamic customization and targeting capabilities , ATG lets you drive cross-channel sales and marketing from a single platform — even for multiple brands, and across multiple geographies.

ATG provides direct control over user-friendly website management tools to various marketers and merchandisers. You can choose your delivery model as licensed e-commerce software, or a fully hosted on demand solution.
 

To learn more, you can visit http://www.atg.com and discover the comprehensive feature list they provide.
 

(The author, Jagadish, is a Software Engineer at Binary Spectrum)


 

 

April 17, 2009

Agile practices - Requirement to Implementation

- Anjana.M 

 

We often see programmers jump to their seats and start coding as soon as they just hear any requirement. They may be able to complete the task, but may actually be lost in fixing the logical errors for a long time.

I have followed this approach that I am stating below, and yes, it worked well. I also believe that this is a stress free approach towards developing and implementing the requirement.

This is just doing object modeling in a well planned way. This surely can be achieved with UML tools. But paper work at times does prove to be quicker.

Let me know your thoughts on it and looking forward to know your development approaches as well.


Here are the 10 steps for a planned approach:

Step-1: Get requirement

Step-2: Don’t start development as soon as you get the requirement

Step-3: Lets follow the divide and rule approach - Divide the requirement into subtasks! We may have a list of subtasks

Step-4: Rule Them -Recognize the dependent task

Step-5: Create a class with requirement's name

Step-6: Make the subtasks as methods in the class

Step-7: Recognize the Inputs and Outputs for each method

Step-8: Build the DBQUERY

Step-9: Include the logic

Step-10: Unit test with SOP for each method in the class.

 

(The author, Anjana.M, is a Software Engineer at Binary Spectrum) 

 

April 13, 2009

STORED PROCEDURES FOR NOVICE (BEGINNERS) IN SQL SERVER 2005

-Tauseef. M

 

As the saying goes, “Necessity is the mother of invention. It is true, but its father is creativity, and knowledge is the midwife"; Well guy's I am very happy to share my knowledge too regarding stored Procedures. For now, I have decided to write a preliminary description on Stored Procedure in SQL Server 2005.

 

Starting with what are stored Procedures?

In simple terms "Stored Procedures are a set of already written SQL statements that are saved in the database." If you are executing the same query over and over again, then it would make sense to simply put it into stored procedure.

Furthermore, with a stored procedure, you can store all the logic in the database, and use a simple command to call the stored procedure. Later, if you decide to migrate from ASP to java, J2EE, you only need to change the application layer as much of the business logic will remain in the database.

 

Getting Started with Stored Procedures

  Basic requirements to begin writing stored procedures:

  1. A database Management System (Ex: Sql Server 2005)

  2. A database built inside the database Management System.(Ex : Demo database)

  3. A Query Analyzer which is Built-in into Sql server 2005. You need not worry!!

 

Writing Your First Stored Procedure

So let's begin our countdown, creativity all that matters!!

  1. Open Sql Server 2005

  2. Right click -> Create Database

  3. Enter new Database name (dsp_users)

  4. Now Expand dsp_users, right-click on tables and create a new table with table name as

      dbo.emp_users with the column names as below:

  •          uname     nvarchar(50)
  •          upass     nvarchar(50)
  •          uaddress  nvarchar(50)
  •          uage      int
  •          uid       int

 

 5 Now expand Programmability -> Right click Stored Procedures and select New Stored Procedure.

 Now, here the top section is useful for comments about the stored procedure, a change log, and other pertinent information. While this is not required, it is just a good programming habit

============================================================

-- Author:                            Tauseef

-- Create date:                  09/03/09

-- Description:                  Stored procedure to display results

=========================================================

 

Now just below this, you will create a store procedure. It starts with the keyword CREATE PROCEDURE written as follows:

CREATE PROCEDURE usp_display

/*

We will put the variables in here, if there are any

*/

AS

/*

This is where the actual SQL statements will be written as below

*/

BEGIN

                -- SET NOCOUNT ON added to prevent extra result sets from

                -- interfering with SELECT statements.

                SET NOCOUNT ON;

 

    -- Insert statements for procedure here

                SELECT *from emp_users
END

Here now the stored procedure name is usp_display. usp defines "User Stored Procedure". The above stored procedure displays all the records of the emp_users table.

 

Now in the menu-tab up (Click Query-> Execute) . Now it says “Command completed succesfully" . Thus you have created your first stored procedure.

 

How to execute the created stored procedure?

Its simple, just open a new query and type the following command exec  usp_display and run it. The records of the table emp_users  gets displayed.

 

More Sophisticated Stored Procedures using input and output variables will be explained later.

(The author Tauseef. M, is a Software Developer at Binary Spectrum)

 

 

Privacy | Terms of use | Blog | EMR | EHR | Retail | MS.NET | Wireless | Design | Healthcare Areas | Healthcare Security | Healthcare Stat-license | Retail - Store Operation

 

© 2003 Binary Spectrum All Rights Reserved