for web form

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

/// <summary>
/// Summary description for mydblayer
/// </summary>
public class mydblayer
{
    public SqlConnection con;
    public SqlCommand cmd;
    public SqlDataAdapter da;

    public mydblayer()
    {
        con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
        cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandType = CommandType.StoredProcedure;
        da = new SqlDataAdapter(cmd);
    }
    public bool MyInsertUpdateDelete(string procedureName)
    {
        try
        {
            cmd.CommandText = procedureName;
            if (con.State == ConnectionState.Closed)
                con.Open();
            return cmd.ExecuteNonQuery() > 0 ? true : false;
        }
        catch (Exception ex)
        {
            string str = ex.ToString();
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
                con.Close();
        }
    }
    public DataTable selectbulkrecord(string procedureName)
    {
        try
        {
            DataTable dt = new DataTable();
            cmd.CommandText = procedureName;
            da.Fill(dt);
            return dt;
        }
        catch (Exception e)
        {
            string str = e.ToString();
            return new DataTable();
        }
    }
}

Comments

Popular posts from this blog

Grideview on row command

Image Show on change of fileupload

Encription Manager In Asp.net