Friday, 7 August 2015

GridView Bind With DataBase in Asp.Net Application

GridView Bind With DataBase in Asp.Net Application

--------------------------------------------------------------------------------------------------------------------------

PART-1

1st Step:- Create DataBase Like Image...


Sql Queries :-----
                     create Database GridViewConcept

use GridViewConcept

create table Student
(
RollNo int Primary Key,
Name nvarchar(50),
Class nvarchar(50),
Subject nvarchar(50),
MobileNo nvarchar(50),
City nvarchar(50)
)
select * from Student

insert into Student values(1,'RAM','BA','ARTS','8765432545','Patna')
insert into Student values(2,'SHYAM','BSC','Math','8765432545','Patna')
insert into Student values(3,'MOHAN','BA','History','8765432545','Patna')
insert into Student values(4,'SOHAN','BSC','Phy','8765432545','Patna')

-------------------------------------------------------------------------------------------------------------------------

PART-2

1st Step:- 
  1. Add/Create Empty Asp .Net Application
  2. Add/Create Web Form Like this Image

 Create Design Like this Image



After Designing Then Code For ADD Button Values into DataBase.

 protected void btnADD_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection _con = new SqlConnection("Data Source=.;Initial Catalog=GridViewConcept;Integrated Security=True");
                _con.Open();
                SqlCommand _cmd = new SqlCommand("Insert Into StudentRecord Values ("+Convert.ToString(txtRollNo.Text)+",'"+txtName.Text+"','"+txtClass.Text+"','"+txtSubject.Text+"','"+txtMobileNo.Text+"','"+txtCity.Text+"')", _con);
                int res = _cmd.ExecuteNonQuery();
                lblmASSAGE.Visible = true;
                lblmASSAGE.ForeColor = Color.Green;
                lblmASSAGE.Text = "Successfully SAVED";
                _con.Close();
            }
            catch (Exception ex)
            {
                
                lblmASSAGE.Visible=true;
                lblmASSAGE.ForeColor =Color.Red;
                lblmASSAGE.Text = ex.ToString();
            }
        }


--Code For Bind The GridView on click of SHOW Button ..

 protected void btnSHOW_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection _con = new SqlConnection("Data Source=.;Initial Catalog=GridViewConcept;Integrated Security=True");
                _con.Open();
                SqlCommand _cmd = new SqlCommand("SELECT * FROM StudentRecord", _con);
                SqlDataReader dr = _cmd.ExecuteReader();
                GridView1.DataSource = dr;
                GridView1.DataBind();
                _con.Close();
                

            }
            catch (Exception ex)
            {
                lblmASSAGE.Visible = true;
                lblmASSAGE.ForeColor = Color.Red;
                lblmASSAGE.Text = ex.ToString();
            }

        }


---Then Execute The Application




----Fill and Add button Click then Show Button Click value will be show into the Gridview Pannel...


...................................................................................................................................................................

Monday, 3 August 2015

PRIME NUMBER BETWEEN 1 TO 100 IN CONSOLE APPLICATION

PRIME NUMBER BETWEEN 1 TO 100 IN CONSOLE APPLICATION
1.       1 Step – Take/Add a Console Application in Visual Studio.


1    2        Write The Code For The Prime Numbers Between 1 To 100.


2    3       Code…..
//……………………………………………………………………..//
static void Main(string[] args)
        {
            bool IsPrime = true;
            Console.WriteLine ("Prime numbers :");
            for (int i = 2; i <= 100; i++)
            {
                for (int j = 2; j < 100; j++)
                {
                    If (i !=j && i%j ==0)
                    {
                        IsPrime = false;
                        break;
                    }
                }

                if (IsPrime)
                {
                    Console.Write("\t" + i);
                }
                IsPrime = true;
            }
            Console.ReadKey();   
        }
//……………………………………………………………………………………………………………………………………………………………………//

 4-Source Code (Image-1)


5- Output (Image-2)


6- Enjoy the Program





Factorial of a Number

Recently Viewed