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"); }
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
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();
}
}
}
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
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

