Posted by : Sudhir Chekuri Sunday, 26 February 2017

SQL Queries


create Table Tbl_Category (CategoryId bigint Primary key identity, CategoryName varchar(100),CreatedTime datetime)

insert Tbl_Category values('Electronics',getdate())
insert Tbl_Category values('Home Appliances',getdate())
insert Tbl_Category values('Books',getdate())
insert Tbl_Category values('Fashion and Life Style',getdate())

select * from Tbl_Category

create Table Tbl_SubCategory (SubcategoryId bigint Primary key identity,SubCatCategoryId bigint foreign key references Tbl_Category(CategoryId),
SubcategoryName varchar(100),createdtime datetime)

insert  Tbl_SubCategory values ('1','Air Conditioners',getdate())
insert  Tbl_SubCategory values ('1','LEDs',getdate())
insert  Tbl_SubCategory values ('1','Mobiles',getdate())
insert  Tbl_SubCategory values ('1','Others',getdate())
insert  Tbl_SubCategory values ('2','Mixer',getdate())
insert  Tbl_SubCategory values ('2','Grinder',getdate())
insert  Tbl_SubCategory values ('2','Microwave',getdate())
insert  Tbl_SubCategory values ('2','Fridge',getdate())

select * from Tbl_SubCategory

ASP.NET Source Code


  <asp:DropDownList ID="DDLCatagories" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DDLCatagories_SelectedIndexChanged">
                </asp:DropDownList>

 <asp:DropDownList ID="DDLSubCatagories" runat="server">
                   
                </asp:DropDownList>

ASP.NET C# Code

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

namespace BIGGERR.Customer
{
    public partial class CustomerProducts : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DisplayCategory();
            }
        }
        public void DisplayCategory()
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["BiggerrConnection"].ConnectionString);
            string s = "select * from Tbl_Category";

            SqlCommand cmd = new SqlCommand(s, con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);

            DDLCatagories.DataSource = ds;
            DDLCatagories.DataValueField = "CategoryId";
            DDLCatagories.DataTextField = "CategoryName";
            DDLCatagories.DataBind();
            
        }

        protected void DDLCatagories_SelectedIndexChanged(object sender, EventArgs e)
        {

            DisplaySubCategory();
        }

        public void DisplaySubCategory()
        { 
         SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["BiggerrConnection"].ConnectionString);
            string s = "select * from Tbl_SubCategory where SubCatCategoryId="+DDLCatagories.SelectedValue;

            SqlCommand cmd = new SqlCommand(s, con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);

            DDLSubCatagories.DataSource = ds;
            DDLSubCatagories.DataValueField = "SubcategoryId";
            DDLSubCatagories.DataTextField = "SubcategoryName";
            DDLSubCatagories.DataBind();
        }
    }
}

web.config


<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />

  </system.web>
<connectionStrings>
<add name="BiggerrConnection" connectionString="Data Source=ADMIN\MSSQLSERVERNEW;Initial Catalog=Biggerr;Integrated Security=True;" />
</connectionStrings>
</configuration>


{ 1 comments ... read them below or add one }

  1. Play Slots and Casino Games Online for Free
    › play-slots-and-casino › play-slots-and-casino 광명 출장안마 This guide to online 의정부 출장샵 casino 양주 출장마사지 games offers you a full list of all the exciting free slots machines you can 공주 출장안마 play at different sites and 양주 출장마사지 in a safe and secure way.

    ReplyDelete

Followers

Total Pageviews

Powered by Blogger.

- Copyright © 2013 DevStudent - Metrominimalist - Powered by Blogger - Designed by Johanes Djogan -