Friday 17 August 2012

Convert function for Select only date from datebase



SELECT CONVERT(VARCHAR(10), Dob, 103) as dob from Application

select current date

Select CONVERT(VARCHAR(10), getdate(), 110)

 show data in gridview in   13 August 2012 Formate

                             <td>
                                <%# Eval("DOB", "{0:D}")%>
                            </td>

Thursday 16 August 2012

How to show the progressbar during check the username availability or how to implement username check availabilty like yahoo using asp.net ajax

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Check Username availability Using Ajax</title>
<style type="text/css">
.waitingdiv {
background-color: #F5F8FA;
border: 1px solid #5A768E;
color: #333333;
font-size: 93%;
margin-bottom: 1em;
margin-top: 0.2em;
padding: 8px 12px;
width: 8.4em;
}
</style>

</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="scriptmanager1" runat="server">
</asp:ScriptManager>
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
function BeginRequestHandler(sender, args) {
var state = document.getElementById('loadingdiv').style.display;
if (state == 'block') {
document.getElementById('loadingdiv').style.display = 'none';
} else {
document.getElementById('loadingdiv').style.display = 'block';
}
args.get_postBackElement().disabled = true;
}
</script>
<div>

<asp:UpdatePanel ID="PnlUsrDetails" runat="server">
<ContentTemplate>
<table>
<tr>
<td>
UserName:
</td>
<td>
<asp:TextBox ID="txtUsername" runat="server" AutoPostBack="true" ontextchanged="txtUsername_TextChanged"/>
</td>
<td>
<div id="checkusername" runat="server"  Visible="false">
<asp:Image ID="imgstatus" runat="server" Width="17px" Height="17px"/>
<asp:Label ID="lblStatus" runat="server"></asp:Label>
</div>
</td>
</tr>
</table>
<div class="waitingdiv" id="loadingdiv" style="display:none; margin-left:5.3em">
<img src="LoadingImage.gif" alt="Loading" />Please wait...
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
 
protected void txtUsername_TextChanged(object sender, EventArgs e)
{
if(!string.IsNullOrEmpty(txtUsername.Text))
{
SqlConnection con = new SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB");
con.Open();
SqlCommand cmd = new SqlCommand("select * from UserInformation where UserName=@Name", con);
cmd.Parameters.AddWithValue("@Name", txtUsername.Text);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
checkusername.Visible = true;
imgstatus.ImageUrl = "NotAvailable.jpg";
lblStatus.Text = "UserName Already Taken";
System.Threading.Thread.Sleep(2000);
}
else
{
checkusername.Visible = true;
imgstatus.ImageUrl = "Icon_Available.gif";
lblStatus.Text = "UserName Available";
System.Threading.Thread.Sleep(2000);
}
}
else
{
checkusername.Visible = false;
}
}
 

JQuery disable right click on Image using asp.net


<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>jQuery disable right click on webpage using asp.net</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script type="text/javascript" language="javascript">
    $(function () {
        $('img').bind("contextmenu", function () {
            return false
        });
    });
</script>
  
</head>
<body>
<form id="form1" runat="server">
<img src="Images/Desert.jpg" width="150px" height="100px" alt="you can't write click" />
<div>
Aspdotnet-Suresh offers Asp.net,C#.net,SQL Server,Web Services,WCF,
WPF,MVC,Crystal Reports,AJAX,XML,JavaScript,JQuery,Gridview articles,
samples and tutorials,code examples of asp.net 2.0,3.0,3.5,4.0 and Articles,
examples of .net technologies
</div>
</form>
</body>
</html>

JQuery disable right click on web page using asp.net

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>jQuery disable right click on webpage using asp.net</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script type="text/javascript" language="javascript">
    $(function () {
        $(this).bind("contextmenu", function () {
            return false
        });
    });
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
Aspdotnet-Suresh offers Asp.net,C#.net,SQL Server,Web Services,WCF,
WPF,MVC,Crystal Reports,AJAX,XML,JavaScript,JQuery,Gridview articles,
samples and tutorials,code examples of asp.net 2.0,3.0,3.5,4.0 and Articles,
examples of .net technologies
</div>
</form>
</body>
</html>

Tuesday 7 August 2012

Jquery for Date Picker

<html>
<head><title></title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.8.22/themes/base/jquery-ui.css" type="text/css" media="all" />
            <link rel="stylesheet" href="http://static.jquery.com/ui/css/demo-docs-theme/ui.theme.css" type="text/css" media="all" />
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
            <script src="http://code.jquery.com/ui/1.8.22/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function ($) {


        $(function () {
            $.datepicker.setDefaults($.datepicker.regional[""]);
            $(".datepicker").datepicker({ yearRange: "1901:2050"
, changeMonth: true,
                changeYear: true
            });
          

        });
        // Handler for .ready() called.
    });
    function selectGUniversity_onclick() {

    }

    </script>
</head>
<body>
<table>
<tr>
<td><asp:TextBox ID="txtdob" runat="server" class="datepicker"></asp:TextBox></td>
</tr>
</table>
</body>
</html>

Thursday 2 August 2012

Create Property and method in Class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace Acteon
{
    public class C_Application
    {


        //private System.Int64 _Applicationid;
        private System.String _Name;
        private System.String _Dob;
        private System.String _Gender;
        private System.String _Maritalstatus;
        private System.String _Emailid;
        private System.String _Phoneno;
        private System.String _City;
        private System.String _State;
        private System.String _Mobinno;
        private System.String _Adress;
        private System.String _Currentemployer;
        private System.String _Location;
        private System.String _Totalexperience;
        private System.String _Designation;
        private System.Decimal _Annualsalary;
        private System.String _Resumeurl;
        private Int64 _value;
      
        public System.String Name
        {
            get
            {
                return _Name;
            }
            set
            {
                _Name = value;
            }
        }
        public System.String Dob
        {
            get
            {
                return _Dob;
            }
            set
            {
                _Dob = value;
            }
        }
        public System.String Gender
        {
            get
            {
                return _Gender;
            }
            set
            {
                _Gender = value;
            }
        }
        public System.String Maritalstatus
        {
            get
            {
                return _Maritalstatus;
            }
            set
            {
                _Maritalstatus = value;
            }
        }
        public System.String Emailid
        {
            get
            {
                return _Emailid;
            }
            set
            {
                _Emailid = value;
            }
        }
        public System.String Phoneno
        {
            get
            {
                return _Phoneno;
            }
            set
            {
                _Phoneno = value;
            }
        }
        public System.String City
        {
            get
            {
                return _City;
            }
            set
            {
                _City = value;
            }
        }
        public System.String State
        {
            get
            {
                return _State;
            }
            set
            {
                _State = value;
            }
        }
        public System.String Mobinno
        {
            get
            {
                return _Mobinno;
            }
            set
            {
                _Mobinno = value;
            }
        }
        public System.String Adress
        {
            get
            {
                return _Adress;
            }
            set
            {
                _Adress = value;
            }
        }
        public System.String Currentemployer
        {
            get
            {
                return _Currentemployer;
            }
            set
            {
                _Currentemployer = value;
            }
        }
        public System.String Location
        {
            get
            {
                return _Location;
            }
            set
            {
                _Location = value;
            }
        }
        public System.String Totalexperience
        {
            get
            {
                return _Totalexperience;
            }
            set
            {
                _Totalexperience = value;
            }
        }
        public System.String Designation
        {
            get
            {
                return _Designation;
            }
            set
            {
                _Designation = value;
            }
        }
        public System.Decimal Annualsalary
        {
            get
            {
                return _Annualsalary;
            }
            set
            {
                _Annualsalary = value;
            }
        }
        public System.String Resumeurl
        {
            get
            {
                return _Resumeurl;
            }
            set
            {
                _Resumeurl = value;
            }
        }
        #region Login Property and method

        private string userid;

        public string Userid
        {
            get { return userid; }
            set { userid = value; }
        }
        private string userpass;

        public string Userpass
        {
            get { return userpass; }
            set { userpass = value; }
        }

        private string imagetitle;

        public string Imagetitle
        {
            get { return imagetitle; }
            set { imagetitle = value; }
        }
        private string imagepath;

        public string Imagepath
        {
            get { return imagepath; }
            set { imagepath = value; }
        }
        private Int64 enteredby1;

        public Int64 Enteredby1
        {
            get { return enteredby1; }
            set { enteredby1 = value; }
        }
        private Int64 offerid;

        public Int64 Offerid
        {
            get { return offerid; }
            set { offerid = value; }
        }
        private Int64 counterid;

        public Int64 Counterid
        {
       get { return counterid; }
       set { counterid = value; }
}      
      
        #region MyRegion
        private Int64 _value1;
        private System.Int64 _Qualificationid;
        private System.Int64 _Applicationid;
        private System.String _Coursename;
        private System.String _Universityname;
        private System.String _Passingyear;
        private System.String _Stream;
        private System.Int32 _Isactive;
        private System.DateTime _Enteredon;
        private System.Int64 _Enteredby;
        private System.DateTime _Updatedon;
        private System.Int64 _Updatedby;
        private String _ConnectionString;

        public System.Int64 Qualificationid
        {
            get
            {
                return _Qualificationid;
            }
            set
            {
                _Qualificationid = value;
            }
        }
        public System.Int64 Applicationid
        {
            get
            {
                return _Applicationid;
            }
            set
            {
                _Applicationid = value;
            }
        }
        public System.String Coursename
        {
            get
            {
                return _Coursename;
            }
            set
            {
                _Coursename = value;
            }
        }
        public System.String Universityname
        {
            get
            {
                return _Universityname;
            }
            set
            {
                _Universityname = value;
            }
        }
        public System.String Passingyear
        {
            get
            {
                return _Passingyear;
            }
            set
            {
                _Passingyear = value;
            }
        }
        public System.String Stream
        {
            get
            {
                return _Stream;
            }
            set
            {
                _Stream = value;
            }
        }
        public System.Int32 Isactive
        {
            get
            {
                return _Isactive;
            }
            set
            {
                _Isactive = value;
            }
        }
        public System.DateTime Enteredon
        {
            get
            {
                return _Enteredon;
            }
            set
            {
                _Enteredon = value;
            }
        }
        public System.Int64 Enteredby
        {
            get
            {
                return _Enteredby;
            }
            set
            {
                _Enteredby = value;
            }
        }
        public System.DateTime Updatedon
        {
            get
            {
                return _Updatedon;
            }
            set
            {
                _Updatedon = value;
            }
        }
        public System.Int64 Updatedby
        {
            get
            {
                return _Updatedby;
            }
            set
            {
                _Updatedby = value;
            }
        }
        public String ConnectionString
        {
            get
            {
                return _ConnectionString;
            }
            set
            {
                _ConnectionString = value;
            }
        }
        #endregion



        public DataTable setcounter()
        {

            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "Counter_acteon";
            cmd.CommandType = CommandType.StoredProcedure;

            return Database.getDataTable(cmd);

        }
        public void offer_delete()
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "offer_delete";
            cmd.Parameters.AddWithValue("@offerid", offerid);
            try
            {
                Database.ExecuteNonQry(cmd);
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        public DataSet Image_show()
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "Image_display";
            cmd.CommandType = CommandType.StoredProcedure;
            try
            {
                return Database.getDataSet(cmd);
            }
            catch
            {
                throw;
            }
        }
        public DataSet image_bind()
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "image_show";
            try
            {
                return Database.getDataSet(cmd);
            }
            catch
            {
                throw;
            }
        }
        public void image_insert()
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "offer_insert";
            cmd.Parameters.AddWithValue("@title", imagetitle);
            cmd.Parameters.AddWithValue("@Imgurl", imagepath);
            cmd.Parameters.AddWithValue("@enteredby", enteredby1);
            try
            {
                Database.insertTable(cmd);
            }
            catch (Exception Ex)
            {
                throw Ex;

            }

        }

        public DataSet Adminlogin()
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "admin_logn";
            cmd.Parameters.AddWithValue("@userid", userid);
            cmd.Parameters.AddWithValue("@userpass", userpass);
           
            try
            {
                return Database.getDataSet(cmd);
            }
            catch
            {
                throw;
            }

        }
        public DataSet Grid_reg_bind()
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "user_regisshow";
            try
            {
                return Database.getDataSet(cmd);
            }
            catch
            {
                throw;
            }
           
        }
        public DataSet Grid_app_bind()
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "user_appshow";
            try
            {
                return Database.getDataSet(cmd);
            }
            catch
            {
                throw;
            }
        }

        public DataSet Datalist1_bind(int id)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "regis_select";
            cmd.Parameters.AddWithValue("@id", id);
            return Database.getDataSet(cmd);

        }
        public DataSet Datalist2_bind(int id)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "appi_select";
            cmd.Parameters.AddWithValue("@id", id);
            return Database.getDataSet(cmd);
        }

        public Int64 Insert()
        {

            SqlCommand cmd = new SqlCommand();
          
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "insert_Application";
            cmd.Parameters.AddWithValue("@Name", _Name);
            cmd.Parameters.AddWithValue("@Dob", _Dob);
            cmd.Parameters.AddWithValue("@Gender", _Gender);
            cmd.Parameters.AddWithValue("@Maritalstatus", _Maritalstatus);
            cmd.Parameters.AddWithValue("@Emailid", _Emailid);
            cmd.Parameters.AddWithValue("@Phoneno", _Phoneno);
            cmd.Parameters.AddWithValue("@City", _City);
            cmd.Parameters.AddWithValue("@State", _State);
            cmd.Parameters.AddWithValue("@Mobinno", _Mobinno);
            cmd.Parameters.AddWithValue("@Adress", _Adress);
            cmd.Parameters.AddWithValue("@Currentemployer", _Currentemployer);
            cmd.Parameters.AddWithValue("@Location", _Location);
            cmd.Parameters.AddWithValue("@Totalexperience", _Totalexperience);
            cmd.Parameters.AddWithValue("@Designation", _Designation);
            cmd.Parameters.AddWithValue("@Annualsalary", _Annualsalary);
            cmd.Parameters.AddWithValue("@Resumeurl", _Resumeurl);

            try
            {

                return _value = Convert.ToInt64(Database.insertTable(cmd));
             
            }
            catch (Exception Ex)
            {
              
                throw Ex;

            }
        }

        public void Update()
        {
            SqlCommand cmd = new SqlCommand();
           // cmd.Connection = con;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "Update_Application";
            //cmd.Parameters.Add("@Applicationid", _Applicationid);
            cmd.Parameters.AddWithValue("@Name", _Name);
            cmd.Parameters.AddWithValue("@Dob", _Dob);
            cmd.Parameters.AddWithValue("@Gender", _Gender);
            cmd.Parameters.AddWithValue("@Maritalstatus", _Maritalstatus);
            cmd.Parameters.AddWithValue("@Emailid", _Emailid);
            cmd.Parameters.AddWithValue("@Phoneno", _Phoneno);
            cmd.Parameters.AddWithValue("@City", _City);
            cmd.Parameters.AddWithValue("@State", _State);
            cmd.Parameters.AddWithValue("@Mobinno", _Mobinno);
            cmd.Parameters.AddWithValue("@Adress", _Adress);
            cmd.Parameters.AddWithValue("@Currentemployer", _Currentemployer);
            cmd.Parameters.AddWithValue("@Location", _Location);
            cmd.Parameters.AddWithValue("@Totalexperience", _Totalexperience);
            cmd.Parameters.AddWithValue("@Designation", _Designation);
            cmd.Parameters.AddWithValue("@Annualsalary", _Annualsalary);
            cmd.Parameters.AddWithValue("@Resumeurl", _Resumeurl);
            //cmd.Parameters.Add("@Isative", _Isative);
            //cmd.Parameters.Add("@Enteredon", _Enteredon);
            //cmd.Parameters.Add("@Enteredby", _Enteredby);
            //cmd.Parameters.Add("@Updatedon", _Updatedon);
            //cmd.Parameters.Add("@Updatedby", _Updatedby);

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception Ex)
            {
                throw Ex;

            }
        }

        public Int64 Insertqualification()
        {
          
            SqlCommand cmd = new SqlCommand();
           
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "insert_Qualification";
            cmd.Parameters.AddWithValue("@Applicationid", _Applicationid);
            cmd.Parameters.AddWithValue("@Coursename", _Coursename);
            cmd.Parameters.AddWithValue("@Universityname", _Universityname);
            cmd.Parameters.AddWithValue("@Passingyear", _Passingyear);
            cmd.Parameters.AddWithValue("@Stream", _Stream);
            //cmd.Parameters.Add("@Isactive", _Isactive);
            //cmd.Parameters.Add("@Enteredon", _Enteredon);
            //cmd.Parameters.Add("@Enteredby", _Enteredby);
            //cmd.Parameters.Add("@Updatedon", _Updatedon);
            //cmd.Parameters.Add("@Updatedby", _Updatedby);
            try
            {
                return _value1 = Convert.ToInt64(Database.insertTable(cmd));
         
            }
            catch (Exception Ex)
            {
       
                throw Ex;

            }
        }
    }
}

Create Business Layer in asp.net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Diagnostics;

namespace Acteon
{
    /// <summary>
    /// This is a static class which provides various Methods to read and update the database.
    /// </summary>
    public static class Database
    {
        static String conString;

        /// <summary>
        /// This is a static constructure in which we initialise some static varible.
        /// </summary>
        static Database()
        {

            //System.Configuration.Configuration rootWebConfig =
            //    System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/localhost:54138");

            //System.Configuration.ConnectionStringSettings conString;
            //if (rootWebConfig.ConnectionStrings.ConnectionStrings.Count > 0)
            //{
            //    conString =
            //        rootWebConfig.ConnectionStrings.ConnectionStrings["Silverlight_TestConnectionString"];
            //    //if (conString != null)
            //    //    Console.WriteLine("Northwind connection string = \"{0}\"",
            //    //        conString.ConnectionString);
            //    //else
            //    //    Console.WriteLine("No Northwind connection string");
            //}

            // conString = ConfigurationSettings.GetConfig("ConnectionString");
            var _newString = ConfigurationSettings.GetConfig("aspnet2ConfigurationDemo");

            if (_newString != null)
            {
                conString = (((CustomCon)(_newString)).ConnectionString).ToString();
                //conString = ConfigurationManager.ConnectionStrings["ERP_MainDB"].ConnectionString;}
            }
            else
            {
              //  conString = "Data Source=182.18.185.248;Initial Catalog=ERP;uid=salik;pwd=salik@123";
                  conString = "Data Source=SERVER2008r2\\ONLINE24X7;Initial Catalog=Acteon_website;Integrated Security=true;";
                //conString = "Data Source=server\\ONLINE24X7;Initial Catalog=ERP;uid=salik;pwd=salik@123;Pooling=true;Max Pool Size=20000; Min Pool Size=10000;Connect Timeout=60";
                //conString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

            }

        }
        /// <summary>
        /// This method reads data, from the database; into a DataTable.
        /// </summary>
        /// <param name="query"> T-SQL Or Stored Procedure Call as Query String which need to execute againest the database.</param>
        /// <returns>The resultant DataTable OR null (if Error takes place in process)</returns>
        public static DataTable getTable(string query)
        {
            SqlConnection myConnection = new SqlConnection(conString);
            SqlCommand myCommand = new SqlCommand();

            try
            {
                myCommand.CommandText = query;
                myCommand.Connection = myConnection;
                DataTable tab = new DataTable();

                myConnection.Open();
                tab.Load(myCommand.ExecuteReader());
                return tab;
            }
            catch (Exception ex)
            {
                //Log.Write("Error :" + ex.Message);
                return null;
            }
            finally
            {
                myConnection.Close();
                myConnection.Dispose();
                myCommand.Dispose();
            }
        }


        public static Object getScalerRecord(SqlCommand _cmd)
        {
            object value = null;
            SqlConnection myConnection = new SqlConnection(conString);
            SqlCommand myCommand = _cmd;

            try
            {

                myCommand.Connection = myConnection;

                myConnection.Open();
                value = myCommand.ExecuteScalar();
            }
            catch (Exception ex)
            {
                string str = ex.Message;
                //Log.Write("Error :" + ex.Message);
            }
            finally
            {
                myConnection.Close();
                myConnection.Dispose();
                myCommand.Dispose();
            }

            return value;


        }


        /// <summary>
        /// This method reads a single value, from the database; into a object.
        /// </summary>
        /// <param name="query"> T-SQL Or Stored Procedure Call as Query String which need to execute againest the database.</param>
        /// <returns>The resultant object OR null (if Error takes place in process)</returns>
        public static object getScalar(string query)
        {
            object value = null;
            SqlConnection myConnection = new SqlConnection(conString);
            SqlCommand myCommand = new SqlCommand();

            try
            {
                myCommand.CommandText = query;
                myCommand.Connection = myConnection;

                myConnection.Open();
                value = myCommand.ExecuteScalar();
            }
            catch (Exception ex)
            {
                //Log.Write("Error :" + ex.Message);
            }
            finally
            {
                myConnection.Close();
                myConnection.Dispose();
                myCommand.Dispose();
            }

            return value;
        }


        public static object getScalarWithType(string query, CommandType type, System.Int64 Rolno)
        {
            object value = null;
            SqlConnection myConnection = new SqlConnection(conString);
            SqlCommand myCommand = new SqlCommand();

            try
            {
                myCommand.CommandType = type;
                myCommand.CommandText = query;
                myCommand.Parameters.AddWithValue("@rolno", Rolno);
                myCommand.Connection = myConnection;

                myConnection.Open();
                value = myCommand.ExecuteScalar();
            }
            catch (Exception ex)
            {
                //Log.Write("Error :" + ex.Message);
            }
            finally
            {
                myConnection.Close();
                myConnection.Dispose();
                myCommand.Dispose();
            }

            return value;
        }



        /// <summary>
        /// This method reads data, from the database; into a DataSet.
        /// </summary>
        /// <param name="query"> T-SQL Or Stored Procedure Call as Query String which need to execute againest the database.</param>
        /// <returns>The resultant DataSet OR null (if Error takes place in process)</returns>
        public static DataSet getDataSet(string query)
        {

            SqlConnection myConnection = new SqlConnection(conString);
            SqlCommand myCommand = new SqlCommand();
            SqlDataAdapter da = new SqlDataAdapter(query, myConnection);
            try
            {

                DataSet ds = new DataSet();
                myConnection.Open();
                da.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                //Log.Write("Error :" + ex.Message);
                return null;
            }
            finally
            {
                myConnection.Close();
                myConnection.Dispose();
                da.Dispose();
            }
        }



        /// <summary>
        /// This method reads data, from the database; into a DataSet.
        /// </summary>
        /// <param name="MyCommand"> T-SQL Or Stored Procedure Call as Query String which need to execute againest the database.</param>
        /// <returns>The resultant DataSet OR null (if Error takes place in process)</returns>
        public static DataTable getDataTable(SqlCommand myCommand)
        {

            SqlConnection myConnection = new SqlConnection(conString);
            myCommand.Connection = myConnection;
            SqlDataAdapter da = new SqlDataAdapter(myCommand);
            try
            {

                DataTable dt = new DataTable();
                myConnection.Open();
                da.Fill(dt);
                return dt;
            }
            catch (Exception ex)
            {
                //Log.Write("Error :" + ex.Message);
                return null;
            }
            finally
            {
                myConnection.Close();
                myConnection.Dispose();
                da.Dispose();
            }
        }


        /// <summary>
        /// This method reads data, from the database; into a DataSet.
        /// </summary>
        /// <param name="MyCommand"> T-SQL Or Stored Procedure Call as Query String which need to execute againest the database.</param>
        /// <returns>The resultant DataSet OR null (if Error takes place in process)</returns>
        public static DataSet getDataSet(SqlCommand myCommand)
        {

            SqlConnection myConnection = new SqlConnection(conString);
            myCommand.Connection = myConnection;
            SqlDataAdapter da = new SqlDataAdapter(myCommand);
            try
            {

                DataSet ds = new DataSet();
                myConnection.Open();
                da.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                //Log.Write("Error :" + ex.Message);
                return null;
            }
            finally
            {
                myConnection.Close();
                myConnection.Dispose();
                da.Dispose();
            }
        }

        /// <summary>
        ///  Executes a Transact-SQL statement against the connection and returns the number of rows effected.
        /// </summary>
        /// <param name="query">Transact-SQL statement</param>
        /// <exception cref="System.InvalidOperationException"/>
        /// <exception cref="System.Data.SqlClient.SqlException"/>
        /// <exception cref="System.ArgumentException"/>
        /// <returns> returns the number of rows effected. </returns>
        public static int updateTable(string query)
        {

            int AfectedRows = -1;
            SqlConnection myConnection = new SqlConnection(conString);
            SqlCommand myCommand = new SqlCommand();

            try
            {
                myCommand.CommandText = query;
                myCommand.Connection = myConnection;

                myConnection.Open();
                AfectedRows = myCommand.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                //Log.Write("Error :" + ex.Message);
                throw ex;
            }
            finally
            {
                myConnection.Close();
                myConnection.Dispose();
                myCommand.Dispose();
            }
            return AfectedRows;
        }

        /// <summary>
        ///  Executes a Transact-SQL statement against the connection and returns the number of rows effected.
        /// </summary>
        /// <param name="myCommand">SQLCommand</param>
        /// <exception cref="System.InvalidOperationException"/>
        /// <exception cref="System.Data.SqlClient.SqlException"/>
        /// <exception cref="System.ArgumentException"/>
        /// <returns> returns the number of rows effected. </returns>
        public static int updateTable(SqlCommand myCommand)
        {

          int AfectedRows;
            SqlConnection myConnection = new SqlConnection(conString);

            try
            {
                myCommand.Connection = myConnection;
                myConnection.Open();
                AfectedRows = myCommand.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                //Log.Write("Error :" + ex.Message);
                throw ex;
            }
            finally
            {
                myConnection.Close();
                myConnection.Dispose();
                myCommand.Dispose();
            }
            return AfectedRows;
        }

        /// <summary>
        ///  Executes a Transact-SQL statement against the connection and returns the result of SP as Object.
        /// </summary>
        /// <param name="query">Transact-SQL statement</param>
        /// <exception cref="System.InvalidOperationException"/>
        /// <exception cref="System.Data.SqlClient.SqlException"/>
        /// <exception cref="System.ArgumentException"/>
        /// <returns> returns the output of SP execution. </returns>
        public static object insertTable(string query)
        {

            object returnedResult = null;
            SqlConnection myConnection = new SqlConnection(conString);
            SqlCommand myCommand = new SqlCommand();

            try
            {
                myCommand.CommandText = query;
                myCommand.Connection = myConnection;

                myConnection.Open();
                returnedResult = myCommand.ExecuteScalar();
            }
            catch (Exception ex)
            {
                //Log.Write("Error :" + ex.Message);
                throw ex;
            }
            finally
            {
                myConnection.Close();
                myConnection.Dispose();
                myCommand.Dispose();
            }
            return returnedResult;
        }




        public static Int32 ExecuteNonQry(SqlCommand _cmd)
        {
            object returnedResult = null;
            using (SqlConnection myConnection = new SqlConnection(conString))
            {
                if (myConnection.State == ConnectionState.Closed)
                {
                    myConnection.Open();
                }
                //SqlTransaction _tra = myConnection.BeginTransaction();
                try
                {
                    _cmd.Connection = myConnection;


                    return _cmd.ExecuteNonQuery();

                }
                catch (Exception ex)
                {
                    //Log.Write("Error :" + ex.Message);

                    throw ex;
                }
                finally
                {
                    myConnection.Close();
                    myConnection.Dispose();

                }
                return 0;
            }
        }

        /// <summary>
        ///  Executes a Transact-SQL statement against the connection and returns the number of rows effected.
        /// </summary>
        /// <param name="myCommand">SQLCommand</param>
        /// <exception cref="System.InvalidOperationException"/>
        /// <exception cref="System.Data.SqlClient.SqlException"/>
        /// <exception cref="System.ArgumentException"/>
        /// <returns> returns the number of rows effected. </returns>
        public static object insertTable(SqlCommand myCommand)
        {
            object returnedResult = null;
            using (SqlConnection myConnection = new SqlConnection(conString))
            {
                if (myConnection.State == ConnectionState.Closed)
                {
                    myConnection.Open();
                }
                SqlTransaction _tra = myConnection.BeginTransaction();
                try
                {
                    myCommand.Connection = myConnection;
                    myCommand.Transaction = _tra;

                    returnedResult = myCommand.ExecuteScalar();
                    _tra.Commit();
                }
                catch (Exception ex)
                {
                    //Log.Write("Error :" + ex.Message);
                  _tra.Rollback();
                    throw ex;
                }
                finally
                {
                    myConnection.Close();
                    myConnection.Dispose();
                    myCommand.Dispose();
                }
                return returnedResult;
            }
        }

        //public static Object getScalerRecord(SqlCommand _cmd)
        //{
        //    object value = null;
        //    SqlConnection myConnection = new SqlConnection(conString);
        //    SqlCommand myCommand = _cmd;

        //    try
        //    {

        //        myCommand.Connection = myConnection;

        //        myConnection.Open();
        //        value = myCommand.ExecuteScalar();
        //    }
        //    catch (Exception ex)
        //    {
        //        string str = ex.Message;
        //        //Log.Write("Error :" + ex.Message);
        //    }
        //    finally
        //    {
        //        myConnection.Close();
        //        myConnection.Dispose();
        //        myCommand.Dispose();
        //    }

        //    return value;


        //}


        public static object GetOutPutValue(SqlCommand _cmd, string _outputPerametgerName)
        {
            if (object.ReferenceEquals(_cmd, null))
                throw new Exception("Command object not initialize properly");

            using (_cmd)
            {
                using (SqlConnection _cmon = new SqlConnection(conString))
                {

                    if (_cmon.State == ConnectionState.Closed)
                    {
                        _cmon.Open();

                    }
                    _cmd.Connection = _cmon;
                    _cmd.ExecuteNonQuery();
                    return _cmd.Parameters[_outputPerametgerName].Value;
                }

            }


        }


        public static string[] GetOutPutValue(SqlCommand _cmd, string[] _outputPerametgerName)
        {
            if (object.ReferenceEquals(_cmd, null))
                throw new Exception("Command object not initialize properly");

            using (_cmd)
            {
                using (SqlConnection _cmon = new SqlConnection(conString))
                {

                    if (_cmon.State == ConnectionState.Closed)
                    {
                        _cmon.Open();

                    }
                    _cmd.Connection = _cmon;
                    _cmd.ExecuteNonQuery();
                    List<String> _list = new List<string>();

                    foreach (string _str in _outputPerametgerName)
                    {

                        _list.Add(((string)_cmd.Parameters[_str].Value) ?? "");
                    }
                    return _list.ToArray();
                }

            }


        }
    }
}