Connected Architecture Update

//Connected Architecture - update
        //Update Category
        private void BtnUpdateCategory_Click(object sender, EventArgs e)
        {
            //SqlCommand to update Category
            SqlCommand cmd = new SqlCommand("exec Usp_UpdateCategory '"+CBExistingCategories.Text+"','"+TxtUpdateCategory.Text+"'", con);
            //Open connection
            con.Open();
            //Execute update command
            int i = cmd.ExecuteNonQuery();
            con.Close();

            if (i > 0)
            {
                //Refresh Category list
                PopulateCategories();
                //Show first Category
                CBExistingCategories.SelectedIndex = 0;
                MessageBox.Show("Category Updated Successfully");

            }
            else { MessageBox.Show("Category Not Updated"); }
           
        }


Saturday, 12 March 2016
Posted by Sudhir Chekuri
Tag :

Connected Architecture Insert and Select



SQL Command to create SQL table

CREATE TABLE [dbo].[Tbl_Data](
       [Id] [int] IDENTITY(1,1) NOT NULL,
       [UserName] [varchar](50) NULL,
       [EmailId] [varchar](50) NULL,
       [Password] [varchar](50) NULL,
PRIMARY KEY CLUSTERED
(
       [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

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

ADO.NET C# code to insert data into SQL database table and to view the data
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace mani
{
    public partial class home : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Btn_Insert_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-R72EIR5\SQLEXPRESS;Initial Catalog=mk;Integrated Security=True");
            SqlCommand cmd = new SqlCommand("insert Tbl_Data(Username,EmailId,Password) Values('" + Txt_UserName.Text + "','" + Txt_EmailId.Text + "','" + Txt_Password.Text + "')", con);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            Txt_UserName.Text = "";
            Txt_EmailId.Text = "";
            Txt_Password.Text = "";
            Response.Write("inserted Successfully");

        }

        protected void Btn_Select_Click1(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-R72EIR5\SQLEXPRESS;Initial Catalog=mk;Integrated Security=True");
            SqlCommand cmd = new SqlCommand("Select * From Tbl_Data", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            GV_Select.DataSource = ds;
            GV_Select.DataBind();

        }
    }
}

Posted by Sudhir Chekuri
Tag :

DataTable, DataRow, DataColumns

DataTable is a class which is used to store data in table format which contains rows and columns.
DataRow is the class used to store a row and DataColumns is the class used to store the columns in a DataTable.


Posted by Sudhir Chekuri
Tag :

ExecuteScalar

ExecuteScalar is a method used in connected architecture to execute select command which retrieve a single value from database table. Return type of this method is object which is capable of holding one value that is returning by executing select command.


Posted by Sudhir Chekuri
Tag :

ExecuteNonQuery

ExecuteNonQuery is a method used in connected architecture to execute sql command other than select. Return type of this method is which and it will return number of rows affected in the SQL server by executing the command.

Posted by Sudhir Chekuri
Tag :

ExecuteReader

ExecuteReader is the method used in connected architecture to execute select command that retrieve rows of data from database. SqlDataReader is the return type of it which is capable of holds rows which are returned by executing select command.

Posted by Sudhir Chekuri
Tag :

Connected Architecture

Using connected architecture connection is opened, execute commands and close the connections.
Connection will be in open state till the operations are performed in connected architecture.

3 methods are used to execute sql commands in connected architecture. They are

1. ExecuteReader
2. ExecuteNonQuery
3. ExecuteScalar


Posted by Sudhir Chekuri
Tag :

Followers

Total Pageviews

Powered by Blogger.

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