Wednesday, November 26, 2008

Split and Assemble large file (around 2GB) in C# dot net Programming


Hi friends after a long time I’m back again. Now with a quite different coding flavor in different area. I will express about some operation with File. I will give some code to split and assemble large file. These codes can split up to 2 GB (approximately) file to any number of small file (minimum 1 MB) and also can assemble these small files to get the original file. Be sure that in assembling all small files need to keep in a folder otherwise it will fail to make original file and throw an error.

To do this in C# dot net , I’ve taken help of System.IO namespace and BinaryReader and BinaryWriter class. To learn about these classes please see msdn site. Here I’ve follow very simple algorithm.

For slice a file steps are:
(i) Open a large file in read mode by binary reader stream.
(ii) Execute step iii and step v, until file read reach at end of file.
(iii) Read from that stream and set these bytes in byte array
(iv) Make a new file name from original file name with slice number, for last file slice add ‘E’ after slice number.
(v) Save these bytes from array to a new file with ‘File’ class’s ‘WriteAllBytes’ method.
(vi) close the dot net binary stream.

Download source code from here:
http://alap.me/blog/All_Source_Codes.rar

These code as follows –

(i) BinaryReader br=new BinaryReader(File.Open(filename, FileMode.Open));

(ii) while (br.BaseStream.Length > sliceLen * counter)

(iii) br.BaseStream.Read(buffer, 0, sliceLen);
(iv) curFileName = filename + "." + counter.ToString();
curFileName = filename + "." + counter.ToString() + ".E";
(v) File.WriteAllBytes(curFileName, buffer);
(vi) br.Close();

For assemble these files need to follow these steps –

(i) Create a binary writer stream and open a binary file in append mode.
(ii) Execute from step iii to v
(iii) Generate file name in runtime depends on pervious file name.
(iv) Check for last file slice, last file slice name ends with last character ‘E’. If present file is the last slice then exit from that loop.
(v) Read all bytes from file and set in a byte array then write these byte data by binary writer.
(vi) Close the binary writer.

These code as follows-

(i) BinaryWriter bw = new BinaryWriter(File.Open(orgFile, FileMode.Append))
(ii) while(true)
(iii) nextFileName = orgFile + "." + counter.ToString();
(iv) if (File.Exists(nextFileName + ".E"))

(v) buffer = File.ReadAllBytes(nextFileName + ".E");
bw.Write(buffer);
(vii) bw.Close();

I’ve not covered everything in algorithm but I believe that you will understand these easily.

The complete codes are given below:

// File cutter assembler in microsoft c# dot net
//This code has written by Suman Biswas in 2008.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace FileCutter
{
//This class is used to call the actual file operation class.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Text = "File cutter & assembler (upto 1.96 GB) by Suman Biswas";
}
FileHandling obj = new FileHandling();
private void btnSelectFile_Click(object sender, EventArgs e)
{

obj.SplitUp(SelectFile(),int.Parse(textBox1.Text));


}

private void button1_Click(object sender, EventArgs e)
{
obj.MargeUp(SelectFile());
}
private string SelectFile()
{
OpenFileDialog fbd = new OpenFileDialog();
if (fbd.ShowDialog() != DialogResult.OK)
{
MessageBox.Show("No file selected");
return "";
}
else
return fbd.FileName;
}
}

//Main file operation is done here.
class FileHandling
{
int sliceLen = 1024 * 1024;
int counter = 0;

public void SplitUp(string filename,int fileSizeInMB)
{
if (fileSizeInMB < slicelen =" 1024" counter =" 0;" buffer="new" br="new" slicelen =" (int)br.BaseStream.Length;"> sliceLen * counter)
{
if (br.BaseStream.Length > sliceLen * (counter + 1))
{
br.BaseStream.Read(buffer, 0, sliceLen);
curFileName = filename + "." + counter.ToString();
}
else
{
int remainLen = (int)br.BaseStream.Length - sliceLen * counter;
buffer = new byte[remainLen];
br.BaseStream.Read(buffer, 0, remainLen);
curFileName = filename + "." + counter.ToString() + ".E";
}

if (File.Exists(curFileName))
File.Delete(curFileName);

File.WriteAllBytes(curFileName, buffer);
counter++;
}
br.Close();
MessageBox.Show("File spilitted successfully");
}

public void MargeUp(string firstFileName)
{
if (firstFileName.Length < 1)
return;

string endPart = firstFileName;
string orgFile = "";

orgFile = endPart.Substring(0, endPart.LastIndexOf("."));
endPart = endPart.Substring(endPart.LastIndexOf(".") + 1);

if (endPart == "E")//If only one slice is there
{
orgFile = orgFile.Substring(0, orgFile.LastIndexOf("."));
endPart = "0";
}

if (File.Exists(orgFile))
{
if (MessageBox.Show(orgFile + " already exists, do you want to delete it", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
File.Delete(orgFile);
else
{
MessageBox.Show("File not assembled. Operation cancelled by user.");
return;
}
}

//Assembling starts from here
BinaryWriter bw = new BinaryWriter(File.Open(orgFile, FileMode.Append));
string nextFileName = "";
byte []buffer=new byte [bw.BaseStream.Length];


int counter=int.Parse(endPart);
while(true)
{
nextFileName = orgFile + "." + counter.ToString();
if (File.Exists(nextFileName + ".E"))
{
//Last slice
buffer = File.ReadAllBytes(nextFileName + ".E");
bw.Write(buffer);
break;
}
else
{
buffer = File.ReadAllBytes(nextFileName);
bw.Write(buffer);
}
counter++;
}
bw.Close();
MessageBox.Show("File assebled successfully");
}

}

}

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();
}

}


}