Storeprocedure inc#

STORE PROCEDURE CLASS FILE


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


/// <summary>
/// Summary description for Connection
/// </summary>
public class Connection:Page
{
    public Connection()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    public static SqlConnection con;
    public static SqlDataAdapter adp;
    public static SqlCommand cmd;
    public static SqlDataReader dr;
    public static DataSet ds;
    public static DataTable dt;
    public static SqlConnection Connect()
    {
        try
        {
            string str = ConfigurationManager.ConnectionStrings["HOMEAPPLIANCES"].ToString();
            con = new SqlConnection(str);
        }
        catch (Exception ex)
        {
        }
        return con;
    }

    public DataSet StrngParameter(string query, string[] param, object[] value)
    {
        DataSet ds = new DataSet();
        SqlParameter _objParameter;
        SqlCommand objCmd = new SqlCommand();
        objCmd.Connection = Connect();
        objCmd.CommandType = CommandType.StoredProcedure;
        objCmd.CommandText = query;
        for (int i = 0; i < param.Length; i++)
        {

            _objParameter = new SqlParameter(param[i], value[i]);
            objCmd.Parameters.Add(_objParameter);
        }

        SqlDataAdapter da = new SqlDataAdapter(objCmd);
        da.Fill(ds);
        return ds;
    }
    public void FillDrop(string strQuery, string TextField, string ValueField, DropDownList drp)
    {
        try
        {
            Connect();
            adp = new SqlDataAdapter(strQuery, con);
            ds = new DataSet();
            adp.Fill(ds);
            drp.DataSource = ds;
            drp.DataTextField = ds.Tables[0].Columns[TextField].ToString();
            drp.DataValueField = ds.Tables[0].Columns[ValueField].ToString();
            drp.DataBind();
            drp.Items.Insert(0, new ListItem("SELECT", " "));
        }
        catch { }
    }
    public void FillGrid(string strQuery, GridView grd)
    {
        Connect();
        adp = new SqlDataAdapter(strQuery, con);
        ds = new DataSet();
        adp.Fill(ds);
        grd.DataSource = ds;
        grd.DataBind();
    }
    public bool Check(string tbl, string col, string val)
    {
        Connect();
        adp = new SqlDataAdapter("SELECT "+col+" FROM "+tbl+" WHERE "+col+"='"+val+"'",con);
        dt = new DataTable();
        adp.Fill(dt);
        if (dt.Rows.Count > 0)
            return true;
        else
            return false;
    }
    public bool Check(string query)
    {
        dt = ReturnTable(query);
        if (dt.Rows.Count > 0)
            return true;
        else
            return false;
    }
    public DataTable ReturnTable(string query)
    {
        Connect();
        adp = new SqlDataAdapter(query, con);
        dt = new DataTable();
        adp.Fill(dt);
        return dt;
    }
    public object ReadOneData(string table, string col, string cond)
    {
        dt=ReturnTable("SELECT "+col +" FROM "+table+" "+cond);
        if (dt.Rows.Count > 0)
            return dt.Rows[0][0];
        else
            return null;
    }
    public string SetMaster(string uid)
    {
        int um_type = Convert.ToInt32(ReadOneData("USER_MST", "UM_TYPE", "WHERE UM_UID='" + uid + "'"));
        if (um_type == 1)
            return "../Master/Master.master";
        else
            return "../Master/Master_User.master";
    }
}


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


protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (validate())
        {
            if (ChkDuplicate())
            {
                if (btnSubmit.InnerHtml == "Submit")
                {
                    string[] strparam = { "@Mode", "@IGM_NAME", "@IGM_SHT_NAME", "@IGM_IS_PARENT", "@IGM_PARENT_CODE" };
                    int? parentCode = ddlParentName.SelectedIndex != 0 ? (int?)Convert.ToInt32(ddlParentName.SelectedValue) : null;
                    object[] strvalue = { "InsertItemGrp", txtItmGrpName.Text.ToUpper(), txtItmShtName.Text.ToUpper(), ddlIsParent.Text, parentCode };
                    DataSet ds = con.StrngParameter("SP_ITEM_GRP_MST", strparam, strvalue);
                    if (ds.Tables[0].Rows[0][0].ToString() == "TRUE")
                    {
                        Response.Write("<script>alert('Data Saved Successfully.')</script>");
                        txtItmGrpName.Text = "";
                        txtItmShtName.Text = "";
                    }
                    Init();
                    Grid("All");
                }
                else
                {
                    validate();
                    string[] strparam = { "@Mode", "@IGM_CODE", "@IGM_NAME", "@IGM_SHT_NAME", "@IGM_IS_PARENT", "@IGM_PARENT_CODE" };
                    int? parentCode = ddlParentName.SelectedIndex != 0 ? (int?)Convert.ToInt32(ddlParentName.SelectedValue) : null;
                    object[] strvalue = { "Update", lblIGM_CODE.InnerText, txtItmGrpName.Text.ToUpper(), txtItmShtName.Text.ToUpper(), ddlIsParent.Text, parentCode };
                    DataSet ds = con.StrngParameter("SP_ITEM_GRP_MST", strparam, strvalue);
                    if (ds.Tables[0].Rows[0][0].ToString() == "TRUE")
                    {
                        Response.Write("<script>alert('Data Updated Successfully.')</script>");
                        txtItmGrpName.Text = "";
                        txtItmShtName.Text = "";
                    }
                    Init();
                    Grid("All");
                    btnSubmit.InnerHtml = "Submit";
                }
            }
            else
            {
                Response.Write("<script>alert('Item Group Is Already Exists')</script>");
                txtItmGrpName.Text = "";
                txtItmShtName.Text = "";
                Init();
                Grid("All");
                btnSubmit.InnerHtml = "Submit";
            }
        }
    }

Wednesday, 15 March 2017

Join

        #region GetPostData
        private void GetPostData()
        {
            try
            {
                var post = GetPostList().ToList();
                var user = GetUserList().ToList();
                var comment = GetCommentList().ToList();
                var like = GetLikeList().ToList();              
                         
                             select new
                             {
                                 a.BlogPost_Id,
                                 a.BlogPost_Title,
                                 a.BlogPost_Content,
                                 a.BlogPost_Attachment,
                                 a.BlogPost_Status,
                                 a.BlogPost_PublishedOn,
                                 b.BlogUser_ID,
                                 b.User_Name,
                                 cCountcom= (from cm in comment where cm.BlogPost_Id == a.BlogPost_Id select cm).Count(),
                                 cCountlik = (from lk in like where lk.BlogPost_Id == a.BlogPost_Id select lk).Count(),
                             }).ToList();

                RadListView1.DataSource = null;
                RadListView1.DataSource = query.ToList();
                RadListView1.DataBind();
            }
            catch (Exception)
            {

            }
        }

Tuesday, 7 March 2017

Top 50 SQL Server Questions & Answers

Link

https://www.tutorialspoint.com/sql/index.htm

1. What are the two authentication modes in SQL Server?
There are two authentication modes –
·          Windows Mode
·          Mixed Mode
Modes can be changed by selecting the tools menu of SQL Server configuration properties and choose security page.
2.  What Is SQL Profiler?
SQL Profiler is a tool which allows system administrator to monitor events in the SQL server.  This is mainly used to capture and save data about each event of a file or a table for analysis.
3. What is recursive stored procedure?

Comments

Popular posts from this blog

Create Schema Using C# Asp .Net Dynamically.

How to set Transaction and Roll Back using Entity Framework in C# Code.

How to post image in blob using Windows Azure.