Disconnected Architecture Delete
//Disconnected architecture - delete
//Delete product
private void BtnDeleteProduct_Click(object
sender, EventArgs e)
{
//SqlCommand to delete Product
SqlCommand cmd = new SqlCommand("exec Usp_DeleteProduct
'"+CBExistingCategories.Text+"','"+CBExistingProducts.Text+"'", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
//Update Products
PopulateProducts();
//Clear product details
TxtDescription.Text = "";
NudPrice.Value = 1;
MessageBox.Show("Product Deleted
Successfully");
Disconnected Architecture Update
//Disconnected - update
//Update product name based on the
product name under a category
private void BtnUpdateProduct_Click(object
sender, EventArgs e)
{
//SqlCommand to delete Product
SqlCommand cmd = new SqlCommand("exec Usp_UpdateProduct
'" +
CBExistingCategories.Text + "','" +
CBExistingProducts.Text + "','"+TxtUpdateProduct.Text+"'", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
//Update Products
PopulateProducts();
//Show first item
CBExistingProducts.SelectedIndex = 0;
MessageBox.Show("Product Updated
Successfully");
}
//Disconnected Update
//Update product details
private void BtnAddDetails_Click(object
sender, EventArgs e)
{
//exec Usp_AddProductDetails
'Drinks','Sprites','200 ml sprite chota bottle',25
//SqlCommand to delete Product
SqlCommand cmd = new SqlCommand("exec Usp_AddProductDetails
'" +
CBExistingCategories.Text + "','" +
CBExistingProducts.Text + "','" +
TxtDescription.Text + "',"+NudPrice.Value+"", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
MessageBox.Show("Product details added
Successfully");
Disconnected Architecture Insert
//Disconnected Insert
//Adding product
private void BtnAddProduct_Click(object
sender, EventArgs e)
{
SqlConnection con =new SqlConnection (@"Data Source=DESKTOP-LEBFFH4\PRESS;Initial Catalog=STUDENT;Integrated Security=True");
SqlConnection con =new SqlConnection (@"Data Source=DESKTOP-LEBFFH4\PRESS;Initial Catalog=STUDENT;Integrated Security=True");
//SqlCommand to insert Product
SqlCommand cmd = new SqlCommand("exec Usp_InsertProduct
'" +
CBExistingCategories.Text + "','" +
TxtAddProduct.Text + "','" + TxtDescription.Text + "'," + NudPrice.Value+ "", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
MessageBox.Show("Product Added
Successfully");
Disconnected Architecture Select
//Disconnected - Select
//Populate the datagridview with
registered users information
public void GetData()
{
SqlConnection con =new SqlConnection (@"Data Source=DESKTOP-LEBFFH4\PRESS;Initial Catalog=STUDENT;Integrated Security=True");
SqlConnection con =new SqlConnection (@"Data Source=DESKTOP-LEBFFH4\PRESS;Initial Catalog=STUDENT;Integrated Security=True");
//SqlCommand to insert Category
SqlCommand cmd = new SqlCommand("select * from
Tbl_Register",
con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds, "Users");
//Display users table in
DataGridView
DGVUsers.DataSource = ds.Tables["Users"];
}
//Disconnected - select
//Populate Products
public void PopulateProducts()
{
SqlConnection con =new SqlConnection (@"Data Source=DESKTOP-LEBFFH4\PRESS;Initial Catalog=STUDENT;Integrated Security=True");
SqlConnection con =new SqlConnection (@"Data Source=DESKTOP-LEBFFH4\PRESS;Initial Catalog=STUDENT;Integrated Security=True");
//SqlCommand to get products
SqlCommand cmd = new SqlCommand("exec Usp_GetProducts '"+CBExistingCategories.Text+"'", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds,"Products");
//Clear existing Products
CBExistingProducts.Items.Clear();
//Adding Products to combobox
for(int
i=0;i<ds.Tables["Products"].Rows.Count;i++)
{
//Add categories
to Combobox
CBExistingProducts.Items.Add(ds.Tables["Products"].Rows[i]["ProductName"]);
}
DataSet
DataSet is used in disconnected architecture to store database tables. It can hold multiple tables in it. It is used to store information retrieved by DataAdapter in disconnected architecture. Data adapter will execute the command and fill the dataset with the data retrieved by execution of SQL command.
Connected Architecture Delete
//Connected architecture - delete
//Delete Category
private void BtnDeleteCategory_Click(object sender, EventArgs e)
{
//SqlCommand to delete Category
SqlCommand cmd = new SqlCommand("exec Usp_DeleteCategory
'" +
CBExistingCategories.Text + "'",
con);
//Open connection
con.Open();
//Execute delete command
int i = cmd.ExecuteNonQuery();
con.Close();
if (i > 0)
{
//Refresh Category list
PopulateCategories();
MessageBox.Show("Category Deleted
Successfully");
}
else { MessageBox.Show("Category Not Deleted"); }
