Showing posts with label Stored Procedure. Show all posts
Showing posts with label Stored Procedure. Show all posts

Tuesday, March 11, 2014

MVC with ADO.Net on MySQL (using Stored Procedure)


I am really excited to share this piece of unique code with you. Really this is different MVC without entity framework and based on traditional ADO.Net and database not even MS SQL its MySQL! Yes I am going to share these different type code with all of you.


Before sharing code I would like to tell a brief background about why I have tried it. I have websites all were built on traditional ASP.Net with ADO.Net and now I am trying to migrate these in MVC. But to move everything in MVC at a time will be a big problem, hence I am trying to do it part by part and I believe with ADO.Net MVC will work great. So I do not need to modify database or database access layer. This will reduce my effort and cost.

Next is why MySQL not MS SQL? Reason is, I have small budget for these websites and MS SQL express great for this for now. But in future if I need database more than 10GB or 1GB RAM support for better database operation then MS SQL Express will be a bar for me and paid version is seems very costly according to INR currency. But MySQL enterprise also is free to use and this I am using since last more than 1 year in production on Windows 2008 server without any single problem. About to decide MySQL I get confidence from Google, Facebook, Yahoo etc. companies because so far I know they are all doing their work on MySQL only.

I believe it was a nice explanation about background, now lets come on coding part.

Coding with MySQL is almost similar to MS SQL on .Net part. Just you need to add some reference of MySQL's ADO.Net DLLs and next you need to use MySQL name space in your code. For connection, command, DataAdapter you need to refer MySQL connection, MySQL Command and MySQLDataAdapter. Your calling process and other part will be exactly same. DataTable, DataSet will be same as MS SQL.
In the picture you can see I have added 4 dll files to enable MySQL database access. In MySQL website they share DLLs for specific .Net versions. I am using .Net 4.5 hence I took this files. Files are in source code so for .Net 4.5 you can use these file in your project.






















To access MySQL database I have setup my connection string like below:

<add name="connStr" connectionString="server=localhost;user=root;database=world;port=3306;password=****" providerName="MySql.Data.MySqlClient"/>

My project structure as below:




In this screenshot AllCountries.xshtml is my view in Razor format, CountryController.cs is my controller and Contry.cs is my model where I have written my data access code. Its exactly similar like other ADO.Net data access code. 






















I am using MySQL's provided database (schema) 'world' for my example. 'world' schema is containing one table 'country' and it is containing data about countries, I am going to use these to show my example. Table structure is very simple and it is as below




To get data from 'country' table I have developed 'GetCountryList' Stored Procedure which I shall call from code.

USE `world`;


DELIMITER $$ 
USE `world`$$ 
CREATE DEFINER=`root`@`localhost` PROCEDURE `GetCountryList`( ) 
  BEGIN  
       select * from world.country; 
  END$$ 
DELIMITER ;

My model class - 'Country.cs' as below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;
using System.Configuration;
using System.Web.Security;

namespace World
{
    public class Country
    {
        string connStr;
        MySqlConnection cnn;
        MySqlCommand cmd;
        public Country()
        {
            connStr = ConfigurationManager.ConnectionStrings["connStr"].ToString();
            cnn = new MySqlConnection(connStr);
        }

        public DataTable GetCountryList()
        {
            DataTable dt = new DataTable();
            cmd = new MySqlCommand("GetCountryList");
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection = cnn;

            MySqlDataAdapter adap = new MySqlDataAdapter(cmd);
            if (cnn.State != ConnectionState.Open ||
                cnn.State == ConnectionState.Broken ||
                cnn.State != ConnectionState.Connecting ||
                cnn.State != ConnectionState.Executing ||
                cnn.State != ConnectionState.Fetching)
                try
                {
                    adap.Fill(dt);
                    return dt;
                }
                catch (Exception ex)
                {
                    if (cnn.State != ConnectionState.Closed)
                    {
                        cnn.Close();
                    }
                }
            return dt;
        }
    }   
}

This model class is invoking stored procedure 'GetCountryList' and fetching data from database. Class is completely similar with my earlier project's data access layer class and there has no change, I am using it directly. To show as an example I made is simple with single stored procedure. There has some difference to access MySQL with MS SQL. Look for below codes
using MySql.Data.MySqlClient;

Here I am using MySQLClient which we generally use SqlClient for MS SQL database and declaring MySQL Command, Connection and DataAdapter as below:

MySqlConnection cnn;MySqlCommand cmd;MySqlDataAdapter adap = new MySqlDataAdapter(cmd);


CountryController.cs

Controller class for my project is very simple. This is just creating an object of my country class and invoking method to get data. This method will return a datatable and data table is sending to View.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using World;
namespace MVC4.Controllers
{
    public class CountryController : Controller
    {
        public ActionResult AllCountries()
        {
            Country countries = new Country();
            return View(countries.GetCountryList());
        }
    }
}

View - AllCountries.cshtml, I am using Razor syntax to populate data in view and this is standalone/complete view without any layout of any other partial views. Code as below:

@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>AllCountries</title>
</head>
<body>
    <div>
        <table border="1" cellpadding="5">
            <thead>
                <tr>
                    @foreach (System.Data.DataColumn col in Model.Columns)
                    {
                        <th>@col.Caption</th>
                    }
                </tr>
            </thead>
            <tbody>
                @foreach (System.Data.DataRow row in Model.Rows)
                {
                    <tr>
                        @foreach (var cell in row.ItemArray)
                        {
                            <td>@cell.ToString()</td>
                        }
                    </tr>
                }
            </tbody>
        </table>
    </div>
</body>
</html>
This is very simple code, Razor code is reading DataTable columns and priting these on html by below code. Razor is nothing new, its just earlier traditional things with new name with an @ sign. 
@foreach (System.Data.DataColumn col in Model.Columns)
{
         <th>@col.Caption</th>
}
This is normal foreach loop to print column caption.
Below code is another foreach loop which is going through each cell and printing these.
@foreach (System.Data.DataRow row in Model.Rows)
{
    <tr>
        @foreach (var cell in row.ItemArray)
        {
            <td>@cell.ToString()</td>
        }
    </tr>
}
After executing these codes, output will show like below.



Thank you for reading my blog. You can download full source code from here.





Friday, April 11, 2008

Run any Stored Procedure from .Net - version 2

Please change "(less than)" with it's sign.


In my last article I found some limitation and this code also quite large so I’ve write it’s modified code to run stored procedure. It’s more powerful and comparatively very low code and use is also very easy.


When you run a stored procedure by that code you need to call one function to run specific stored procedure and for every argument need to call just a function. Also here I’ve handle arraylist internally which was need to use externally by you. Also you can use ADO.Net ’s enum to provide table’s field data type and parameter direction also you can use ado.net enum.


Hove ever I’m giving one sample code which you need to write. It’s very easy, just create an object of that class, then invoke these functions. Codes are below:

Create object.

ExecSpClass objSp = new ExecSpClass("Connection string write here");

Pass arguments:

objSp.AddArgument("@nextName", "Suman Biswas", SqlDbType.VarChar, ParameterDirection.Input);

objSp.AddArgument("@id", "2",SqlDbType.Int,ParameterDirection.Input);

Now execute stored procedure:

objSp.ExecSpNonQuery("spProjectCategoryAdd");

Code is complete from your side to run a stored procedure.

I’m giving my code below which is doing the actual work, to learn it you can read it, I think it’s quite easy to understand.

public class ExecSpClass

{

internal class SPArgBuild

{

internal string parameterName = "";

internal string parameterValue = "";

internal SqlDbType pramValueType;

internal ParameterDirection parmDirection;

internal SPArgBuild(string pramName, string pramValue, SqlDbType pramValueType, ParameterDirection parmDirection )

{

this.parameterName = pramName;

this.parameterValue = pramValue;

this.pramValueType = pramValueType;

this.parmDirection = parmDirection;

}

}

SqlConnection conn;

SqlCommand cmd;

SqlDataAdapter adap;

ArrayList spPramArrList = new ArrayList();

public ExecSpClass(string dbConnStr)

{

conn = new SqlConnection(dbConnStr);

}

private void OpenConection()

{

cmd = new SqlCommand();

adap = new SqlDataAdapter(cmd);

cmd.CommandType = CommandType.StoredProcedure;

cmd.Connection = conn;

if (conn.State == ConnectionState.Closed ||

conn.State == ConnectionState.Broken ||

conn.State == ConnectionState.Connecting ||

conn.State != ConnectionState.Executing ||

conn.State != ConnectionState.Fetching ||

conn.State != ConnectionState.Open)

{

conn.Open();

}

}

private void CloseConnection()

{

if (conn.State != ConnectionState.Closed ||

conn.State == ConnectionState.Broken ||

conn.State == ConnectionState.Connecting ||

conn.State != ConnectionState.Executing ||

conn.State != ConnectionState.Fetching ||

conn.State == ConnectionState.Open)

{

conn.Close();

cmd.Dispose();

adap.Dispose();

}

}

public void AddArgument(string spParmName, string spParmValue, SqlDbType spPramValueType, ParameterDirection parmDirection)

{

SPArgBuild spArgBuiltObj = new SPArgBuild(spParmName, spParmValue, spPramValueType,parmDirection);

spPramArrList.Add(spArgBuiltObj);

}

public DataTable ExecSpGetDataTable(string spName)

{

string spPramName = "";

string spPramValue = "";

SqlDbType spPramDataType;

DataSet ds=new DataSet();

OpenConection();

cmd.CommandText = spName;

for (int i = 0; i (less than) spPramArrList.Count; i++)

{

spPramName = ((SPArgBuild)spPramArrList[i]).parameterName;

spPramValue = ((SPArgBuild)spPramArrList[i]).parameterValue;

spPramDataType = ((SPArgBuild)spPramArrList[i]).pramValueType;

SqlParameter pram = null;

pram = cmd.Parameters.Add(spPramName, spPramDataType);

pram.Value = spPramValue;

pram.Direction = ((SPArgBuild)spPramArrList[i]).parmDirection;

}

SqlDataAdapter adap = new SqlDataAdapter(cmd);

adap.Fill(ds);

CloseConnection();

return ds.Tables[0];

}

public string ExecSpScalar(string spName)

{

string spPramName = "";

string spPramValue = "";

OpenConection();

cmd.CommandText = spName;

SqlDbType spPramDataType;

for (int i = 0; i (less than) spPramArrList.Count; i++)

{

spPramName = ((SPArgBuild)spPramArrList[i]).parameterName;

spPramValue = ((SPArgBuild)spPramArrList[i]).parameterValue;

spPramDataType = ((SPArgBuild)spPramArrList[i]).pramValueType;

SqlParameter pram = null;

pram = cmd.Parameters.Add(spPramName, spPramDataType);

pram.Value = spPramValue;

pram.Direction = ((SPArgBuild)spPramArrList[i]).parmDirection;

}

string noRowEfect = cmd.ExecuteScalar().ToString();

CloseConnection();

return noRowEfect;

}

public int ExecSpNonQuery(string spName)

{

string spPramName = "";

string spPramValue = "";

OpenConection();

cmd.CommandText = spName;

SqlDbType spPramDataType ;

for (int i = 0; i (less than) spPramArrList.Count; i++)

{

spPramName = ((SPArgBuild)spPramArrList[i]).parameterName;

spPramValue = ((SPArgBuild)spPramArrList[i]).parameterValue;

spPramDataType = ((SPArgBuild)spPramArrList[i]).pramValueType;

SqlParameter pram = null;

pram = cmd.Parameters.Add(spPramName, spPramDataType);

pram.Value = spPramValue;

pram.Direction = ((SPArgBuild)spPramArrList[i]).parmDirection;

}

int noRowEfect= cmd.ExecuteNonQuery();

CloseConnection();

return noRowEfect;

}

}

If you get any problem to run that code or understand please contact with me.

Saturday, February 23, 2008

Run any Stored Procedure from .Net

NOTE: When I am tring to publish that post then getting some problem for HTML rendering so I replace two character. please replace these two character. HTML opening tag with * and HTML closing tag with $.


Hi, Now I’m far from socket now Im giving some code with .Net and SQL Server related code, that code will help any one to run stored procedure, very easyly with little code. Now follow these code.

Create a table to test the stored procedure, I’m giving one example:

CREATE TABLE client(
id int IDENTITY(1,1) NOT NULL,
Name varchar(64) NULL,
jdate datetime NULL
)

Then insert some data into that table.

INSERT INTO client(Name,jdate)VALUES ('Taniya',getdate())
INSERT INTO client(Name,jdate)VALUES ('Jhuma',getdate())
INSERT INTO client(Name,jdate)VALUES ('Ganesh',getdate())


Then create a stored procedure to test my class, here I’m creating a stored procedure (sp) to update some data based on client id. Here store procedure’s parameters are @nextName and @id. Code is giving here:

create procedure UpdateName ( @nextName varchar(256), @id int )
as
update client set name=@nextName where id=@id


Now sql server data base related job is done. Now will to c# related code.

First giving the code by that my class will be accessed to run that stored procedure. Just note that code, only that code will be required to run any stored procedure.

public class RunSP
{
/// *summary$
/// Run Store Procedure.
/// */summary$
/// *param name="cnnStr"$Connection String of SQL server*/param$
public static void RunSP(string cnnStr)
{
//Create a array list to store parameter(s) with
//parameter name, value & data type.
ArrayList arLst = new ArrayList();
//Now send array list name, value & varchar, persingle
//call of that function will create one stored parameter.
SP.spArgumentsCollection(arLst, "@nextName", "Suman Biswas", "varchar");
SP.spArgumentsCollection(arLst, "@id", "2", "int");
//Now run stored procedure.
SP.RunStoredProcedure(cnnStr, "UpdateName", arLst);
}
}


Here the actual class to run stored procedure, you can make all dll file by that code and then easily use this. Codes are below:

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.SqlClient;

//That code has written by Suman Biswas, that code is running fine at my testing,
//if any one get any problem please inform me. My email is sumanbiswas@aol.in
namespace StoredProcedureLib
{
/// *summary$
/// This class helps to built SP argument. It can use directly to any SP. Created by Suman Biswas on 23rd Frb 2007.
/// */summary$

public class SP
{

internal class SPArgBuild
{
internal string parameterName = "";
internal string parameterValue = "";
/// *summary$
/// Write full data type, such as SqlDBType.VarChar.
/// */summary$
internal string pramValueType = "";

/// *summary$
/// Use to create SP Argument Build conestruction.
/// */summary$
/// *param name="pramName"$SP Argument Parameter Name.*/param$
/// *param name="pramValue"$SP Argument Parameter Value.*/param$
internal SPArgBuild(string pramName, string pramValue, string pramValueType)
{
this.parameterName = pramName;
this.parameterValue = pramValue;
this.pramValueType = pramValueType;

}
}

/// *summary$
/// This function built an Array List, which is collection of some SP parameter's Name, Value and Data type.
/// */summary$
/// *param name="arrLst"$Array List which will store all argument.*/param$
/// *param name="spParmName"$SP Argument Parameter Name.*/param$
/// *param name="spParmValue"$SP Argument Parameter Value.*/param$
/// *param name="spPramValueType"$Parameter value type EXACTLY same as SqlDBType. E.g. 'SqlDbType.BigInt' will 'BigInt'. */param$
/// *returns$*/returns$
public static ArrayList spArgumentsCollection(ArrayList arrLst, string spParmName, string spParmValue, string spPramValueType)
{
SPArgBuild spArgBuiltObj = new SPArgBuild(spParmName, spParmValue, spPramValueType);
arrLst.Add(spArgBuiltObj);
return arrLst;
}

/// *summary$
/// Run a stored procedure of Select SQL type.
/// */summary$
/// *param name="dbConnStr"$Connection String to connect Sql Server*/param$
/// *param name="ds"$DataSet which will return after filling Data*/param$
/// *param name="spName"$Stored Procedure Name*/param$
/// *param name="spPramArrList"$Parameters in ArrayList*/param$
/// *returns$Return DataSet after filing data by SQL.*/returns$
public static DataSet RunStoredProcedure(string dbConnStr, DataSet ds, string spName, ArrayList spPramArrList)
{
SqlConnection conn = new SqlConnection(dbConnStr);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
cmd.CommandText = spName;

string spPramName = "";
string spPramValue = "";
string spPramDataType = "";
for (int i = 0; i * spPramArrList.Count; i++)
{
spPramName = ((SPArgBuild)spPramArrListi).parameterName;
spPramValue = ((SPArgBuild)spPramArrListi).parameterValue;
spPramDataType = ((SPArgBuild)spPramArrListi).pramValueType;
SqlParameter pram = null;
#region SQL DB TYPE AND VALUE ASSIGNMENT
switch (spPramDataType.ToUpper())
{
case "BIGINT":
pram = cmd.Parameters.Add(spPramName, SqlDbType.BigInt);
pram.Value = spPramValue;
break;

case "BINARY":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Binary);
pram.Value = spPramValue;
break;

case "BIT":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Bit);
pram.Value = spPramValue;
break;

case "CHAR":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Char);
pram.Value = spPramValue;
break;

case "DATETIME":
pram = cmd.Parameters.Add(spPramName, SqlDbType.DateTime);
pram.Value = spPramValue;
break;

case "DECIMAL":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Decimal);
pram.Value = spPramValue;
break;

case "FLOAT":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Float);
pram.Value = spPramValue;
break;

case "IMAGE":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Image);
pram.Value = spPramValue;
break;

case "INT":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Int);
pram.Value = spPramValue;
break;

case "MONEY":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Money);
pram.Value = spPramValue;
break;

case "NCHAR":
pram = cmd.Parameters.Add(spPramName, SqlDbType.NChar);
pram.Value = spPramValue;
break;

case "NTEXT":
pram = cmd.Parameters.Add(spPramName, SqlDbType.NText);
pram.Value = spPramValue;
break;

case "NVARCHAR":
pram = cmd.Parameters.Add(spPramName, SqlDbType.NVarChar);
pram.Value = spPramValue;
break;

case "REAL":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Real);
pram.Value = spPramValue;
break;

case "SMALLDATETIME":
pram = cmd.Parameters.Add(spPramName, SqlDbType.SmallDateTime);
pram.Value = spPramValue;
break;

case "SMALLINT":
pram = cmd.Parameters.Add(spPramName, SqlDbType.SmallInt);
pram.Value = spPramValue;
break;

case "SMALLMONEY":
pram = cmd.Parameters.Add(spPramName, SqlDbType.SmallMoney);
pram.Value = spPramValue;
break;

case "TEXT":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Text);
pram.Value = spPramValue;
break;

case "TIMESTAMP":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Timestamp);
pram.Value = spPramValue;
break;

case "TINYINT":
pram = cmd.Parameters.Add(spPramName, SqlDbType.TinyInt);
pram.Value = spPramValue;
break;

case "UDT":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Udt);
pram.Value = spPramValue;
break;

case "UMIQUEIDENTIFIER":
pram = cmd.Parameters.Add(spPramName, SqlDbType.UniqueIdentifier);
pram.Value = spPramValue;
break;

case "VARBINARY":
pram = cmd.Parameters.Add(spPramName, SqlDbType.VarBinary);
pram.Value = spPramValue;
break;

case "VARCHAR":
pram = cmd.Parameters.Add(spPramName, SqlDbType.VarChar);
pram.Value = spPramValue;
break;

case "VARIANT":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Variant);
pram.Value = spPramValue;
break;

case "XML":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Xml);
pram.Value = spPramValue;
break;
}
#endregion
pram.Direction = ParameterDirection.Input;
}

SqlDataAdapter adap = new SqlDataAdapter(cmd);

adap.Fill(ds);
return ds;

}

/// *summary$
/// Run a stored procedure which will execure some nonquery SQL.
/// */summary$
/// *param name="dbConnStr"$Connection String to connect Sql Server*/param$
/// *param name="spName"$Stored Procedure Name*/param$
/// *param name="spPramArrList"$Parameters in a ArrayList*/param$
public static void RunStoredProcedure(string dbConnStr, string spName, ArrayList spPramArrList)
{
SqlConnection conn = new SqlConnection(dbConnStr);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
cmd.CommandText = spName;

string spPramName = "";
string spPramValue = "";
string spPramDataType = "";
for (int i = 0; i * spPramArrList.Count; i++)
{
spPramName = ((SPArgBuild)spPramArrListi).parameterName;
spPramValue = ((SPArgBuild)spPramArrListi).parameterValue;
spPramDataType = ((SPArgBuild)spPramArrListi).pramValueType;
SqlParameter pram = null;
#region SQL DB TYPE AND VALUE ASSIGNMENT
switch (spPramDataType.ToUpper())
{
case "BIGINT":
pram = cmd.Parameters.Add(spPramName, SqlDbType.BigInt);
pram.Value = spPramValue;
break;

case "BINARY":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Binary);
pram.Value = spPramValue;
break;

case "BIT":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Bit);
pram.Value = spPramValue;
break;

case "CHAR":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Char);
pram.Value = spPramValue;
break;

case "DATETIME":
pram = cmd.Parameters.Add(spPramName, SqlDbType.DateTime);
pram.Value = spPramValue;
break;

case "DECIMAL":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Decimal);
pram.Value = spPramValue;
break;

case "FLOAT":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Float);
pram.Value = spPramValue;
break;

case "IMAGE":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Image);
pram.Value = spPramValue;
break;

case "INT":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Int);
pram.Value = spPramValue;
break;

case "MONEY":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Money);
pram.Value = spPramValue;
break;

case "NCHAR":
pram = cmd.Parameters.Add(spPramName, SqlDbType.NChar);
pram.Value = spPramValue;
break;

case "NTEXT":
pram = cmd.Parameters.Add(spPramName, SqlDbType.NText);
pram.Value = spPramValue;
break;

case "NVARCHAR":
pram = cmd.Parameters.Add(spPramName, SqlDbType.NVarChar);
pram.Value = spPramValue;
break;

case "REAL":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Real);
pram.Value = spPramValue;
break;

case "SMALLDATETIME":
pram = cmd.Parameters.Add(spPramName, SqlDbType.SmallDateTime);
pram.Value = spPramValue;
break;

case "SMALLINT":
pram = cmd.Parameters.Add(spPramName, SqlDbType.SmallInt);
pram.Value = spPramValue;
break;

case "SMALLMONEY":
pram = cmd.Parameters.Add(spPramName, SqlDbType.SmallMoney);
pram.Value = spPramValue;
break;

case "TEXT":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Text);
pram.Value = spPramValue;
break;

case "TIMESTAMP":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Timestamp);
pram.Value = spPramValue;
break;

case "TINYINT":
pram = cmd.Parameters.Add(spPramName, SqlDbType.TinyInt);
pram.Value = spPramValue;
break;

case "UDT":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Udt);
pram.Value = spPramValue;
break;

case "UMIQUEIDENTIFIER":
pram = cmd.Parameters.Add(spPramName, SqlDbType.UniqueIdentifier);
pram.Value = spPramValue;
break;

case "VARBINARY":
pram = cmd.Parameters.Add(spPramName, SqlDbType.VarBinary);
pram.Value = spPramValue;
break;

case "VARCHAR":
pram = cmd.Parameters.Add(spPramName, SqlDbType.VarChar);
pram.Value = spPramValue;
break;

case "VARIANT":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Variant);
pram.Value = spPramValue;
break;

case "XML":
pram = cmd.Parameters.Add(spPramName, SqlDbType.Xml);
pram.Value = spPramValue;
break;
}
#endregion
pram.Direction = ParameterDirection.Input;
}
cmd.ExecuteNonQuery();
}

}


}