protected void Page_Load(object sender, EventArgs e) { int ID = 0; if (SessionFacade.USERNAME == null) { SessionFacade.PAGEREQUESTED = Request.ServerVariables["HTTP_URL"]; Response.Redirect("Login.aspx"); } else { IBusinessDataAccount _IBusinessDataAccount = GenericFactory <BusinessLayer, IBusinessDataAccount> .CreateInstance(); ID = Convert.ToInt32(Request.QueryString["ID"]); if (ID == 10) { TableName.Text = "Electronics Products"; } else if (ID == 20) { TableName.Text = "Kitchen Products"; } else { TableName.Text = "Luggages"; } ProductsGridView.DataSource = _IBusinessDataAccount.ProductsByID(ID); ProductsGridView.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { string CS = "data source = L\\MSSQLSERVER01; database = Test; integrated security = SSPI"; //string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; using (SqlConnection con = new SqlConnection(CS)) { //SqlCommand cmd = new SqlCommand("Select * from Employee", con); //SqlDataAdapter da = new SqlDataAdapter("spGetProduct", con); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = new SqlCommand("spGetProduct", con); da.SelectCommand.CommandType = CommandType.StoredProcedure; da.SelectCommand.Parameters.AddWithValue("@ProductID", 1) //da.CommandText = "Select * from Employee; Select * from Employee;"; //da.Connection = con; DataSet ds = new DataSet(); da.Fill(ds); ProductsGridView.DataSourse = ds; ProductsGridView.DataBind(); //cmd.ExecuteReader(); //Response.Write("hello"); } Response.Write("hello"); }
protected void Page_Load(object sender, EventArgs e) { string CS = "data source = L\\MSSQLSERVER01; database = Test; integrated security = SSPI"; //string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; using (SqlConnection con = new SqlConnection(CS)) { //SqlCommand cmd = new SqlCommand("Select * from Employee", con); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "Select * from Employee; Select * from Employee;"; cmd.Connection = con; con.Open(); using (SqlDataReader rdr = cmd.ExecuteReader()) { ProductsGridView.DataSourse = rdr; ProductsGridView.DataBind(); while (rdr.NextResult()) { CategoriesGridView.DataSource = rdr; CategoriesGridView.DataBind(); } } //cmd.ExecuteReader(); //Response.Write("hello"); } Response.Write("hello"); }
protected void GetProductsButton_Click(object sender, EventArgs e) { string ConnectionString = ConfigurationManager.ConnectionStrings["SilverCyanide"].ConnectionString; using (SqlConnection connection = new SqlConnection(ConnectionString)) { //Build the query dynamically, by concatenating the text, that the user has //typed into the ProductNameTextBox. This is a bad way of constructing //queries. This line of code will open doors for sql injection attack //SqlCommand cmd = new SqlCommand("Select * from tblProductInventory where ProductName like '" + ProductNameTextBox.Text + "%'", connection); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Parameterized query. @ProductName is the parameter string Command = "Select * from tblProductInventory where ProductName like @ProductName"; SqlCommand cmd = new SqlCommand(Command, connection); // Provide the value for the parameter cmd.Parameters.AddWithValue("@ProductName", ProductNameTextBox.Text + "%"); connection.Open(); ProductsGridView.DataSource = cmd.ExecuteReader(); ProductsGridView.DataBind(); //i'; Delete from tblProductInventory -- //Sql profiler //exec sp_executesql N'Select * from tblProductInventory where ProductName like @ProductName',N'@ProductName nvarchar(39)',@ProductName = N'i''; Delete from tblProductInventory --%' } }
protected void Page_Load(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(_connectionStr)) { con.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM TBLPRODUCTINVENTORY", con); ProductsGridView.DataSource = cmd.ExecuteReader(); ProductsGridView.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { connection.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString(); connection.Open(); command.CommandText = "SELECT * FROM Products"; command.Connection = connection; ProductsGridView.DataSource = dataReader; ProductsGridView.DataBind(); } }
protected void ProductsGridView_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "SelectedRow") { int row = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; ProductsGridView.SelectRow(row); int ID = Convert.ToInt32(ProductsGridView.SelectedValue); //SelectedRow.Text = "You selected the row with Product ID = " + ID; SessionFacade.PAGEREQUESTED = Request.ServerVariables["HTTP_URL"]; Response.Redirect("ViewProducts.aspx?ProductID=" + ID); } }
private void AddBTN_Click(object sender, EventArgs e) { string name = NameBox?.Text; double price = new double(); double weight = new double(); int count = new int(); try { price = double.Parse(PriceBox.Text); weight = double.Parse(WeightBox.Text); count = int.Parse(CountBox.Text); } catch (Exception) { cMessageBox.Show("პროდუქტი ვერ დაემატა!"); } if (CountBox.Text != "") { if (name != null && price != 0 && weight != 0 && count != 0) { ImportedProducts.Add(new ProductsItem(name, weight, price, count)); cMessageBox.Show("პროდუქტი დაემატა!"); NameBox.Text = ""; WeightBox.Text = ""; PriceBox.Text = ""; CountBox.Text = ""; ProductsGridView.Refresh(); } } else { if (name != null && price != 0 && weight != 0) { ImportedProducts.Add(new ProductsItem(name, weight, price)); cMessageBox.Show("პროდუქტი დაემატა!"); NameBox.Text = ""; WeightBox.Text = ""; PriceBox.Text = ""; CountBox.Text = ""; ProductsGridView.Refresh(); } } ProductsGridView.Refresh(); }
protected void GetProductsButton_Click(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(_connectionStr)) { con.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "SELECT * FROM TBLPRODUCTINVENTORY WHERE NAME LIKE @PRODUCTNAME"; cmd.Parameters.AddWithValue("@PRODUCTNAME", ProductNameTextBox.Text + "%"); cmd.Connection = con; ProductsGridView.DataSource = cmd.ExecuteReader(); ProductsGridView.DataBind(); } }
protected void SpecialFunctionButton_Click(object sender, EventArgs e) { string connStr = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; string sql = "SELECT Products.name as 'Product Name', price, quantity, Catagories.name as 'Catagory' FROM Products, Catagories where Products.catagory_id=Catagories.catagory_id and quantity < 11"; SqlConnection con = new SqlConnection(connStr); SqlCommand cmd = new SqlCommand(sql, con); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); ProductsGridView.DataSource = reader; ProductsGridView.DataBind(); con.Close(); }
protected void Page_Load(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(_connectionStr)) { //Create instance of dataAdapter SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM TBLPRODUCTINVENTORY", con); //Create instance of DataSet for storing result in memory DataSet dataSet = new DataSet(); //call fill() which automatically open connection and execute query and close connection adapter.Fill(dataSet); ProductsGridView.DataSource = dataSet; ProductsGridView.DataBind(); } }
private void LoadProducts() { string connStr = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; string sql = "SELECT Products.name as 'Product Name', price, quantity, Catagories.name as 'Catagory' FROM Products, Catagories where Products.catagory_id=Catagories.catagory_id"; //string sql = "select * from Products, Catagories where Products.catagory_id=Catagories.catagory_id"; SqlConnection con = new SqlConnection(connStr); SqlCommand cmd = new SqlCommand(sql, con); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); ProductsGridView.DataSource = reader; ProductsGridView.DataBind(); con.Close(); }
protected void Page_Load(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(_connectionStr)) { //Create instance of dataAdapter SqlDataAdapter adapter = new SqlDataAdapter("spGetProductInventory", con); adapter.SelectCommand.CommandType = CommandType.StoredProcedure; //Create instance of DataSet for storing result in memory DataSet dataSet = new DataSet(); //call fill() which automatically open connection and execute query and close connection adapter.Fill(dataSet); ProductsGridView.DataSource = dataSet; ProductsGridView.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { using (ProductsProvider provider = new ProductsProvider()) { ProductsGridView.DataSource = provider.GetList(); ProductsGridView.DataBind(); if (!ProductsGridView.IsCallback) { Product focusedRow = ProductsGridView.GetRow(ProductsGridView.FocusedRowIndex) as Product; if (focusedRow != null) { ProductDetails.LoadContent(focusedRow.Id); } } } }
protected void GetProductsButton_Click(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(_connectionStr)) { con.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; //for creating stored procedure get reference to "https://www.c-sharpcorner.com/article/using-stored-procedures-with-Asp-Net/" //whatever they do in 'SqlManagementStudio' we do it in 'View->SQL Server Object Explorer' cmd.CommandText = "spGetProductsByName"; //Specify Sql command is Stored Procedure cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ProductName", ProductNameTextBox.Text + "%"); ProductsGridView.DataSource = cmd.ExecuteReader(); ProductsGridView.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(_connectionStr)) { //Create instance of dataAdapter SqlDataAdapter adapter = new SqlDataAdapter("SELECT NAME,QTYAVAILABLE FROM TBLPRODUCTINVENTORY" + " WHERE PRODUCTID LIKE @PID", con); // Specify the command type is an SP adapter.SelectCommand.Parameters.AddWithValue("@PID", 2); //Create instance of DataSet for storing result in memory DataSet dataSet = new DataSet(); //call fill() which automatically open connection and execute query and close connection adapter.Fill(dataSet); ProductsGridView.DataSource = dataSet; ProductsGridView.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(_connectionStr)) { SqlCommand cmd = new SqlCommand("SELECT * FROM TBLPRODUCTINVENTORY;SELECT * FROM TBLPRODUCTCATEGORIES", con); con.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { ProductsGridView.DataSource = reader; ProductsGridView.DataBind(); while (reader.NextResult()) { CategoriesGridView.DataSource = reader; CategoriesGridView.DataBind(); } } } }
protected void Page_Load(object sender, EventArgs e) { string ConnectionString = ConfigurationManager.ConnectionStrings["MVCDemo"].ConnectionString; using (SqlConnection connection = new SqlConnection(ConnectionString)) { connection.Open(); SqlCommand command = new SqlCommand("select * from tblProductInventory; select * from tblProductCategories", connection); using (SqlDataReader reader = command.ExecuteReader()) { ProductsGridView.DataSource = reader; ProductsGridView.DataBind(); while (reader.NextResult()) { CategoriesGridView.DataSource = reader; CategoriesGridView.DataBind(); } } } }
protected void Page_Load(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection(_connectionStr)) { //Create instance of dataAdapter SqlDataAdapter adapter = new SqlDataAdapter("spGetProductAndCategoriesData", con); //set adapter command type adapter.SelectCommand.CommandType = CommandType.StoredProcedure; //Create instance of DataSet for storing result in memory DataSet dataSet = new DataSet(); //call fill() which automatically open connection and execute query and close connection adapter.Fill(dataSet); dataSet.Tables[0].TableName = "Products"; dataSet.Tables[1].TableName = "Categories"; ProductsGridView.DataSource = dataSet.Tables["Products"]; ProductsGridView.DataBind(); CategoryGridView.DataSource = dataSet.Tables["Categories"]; CategoryGridView.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; using (SqlConnection con = new SqlConnection(CS)) { //executing two sql statements SqlCommand cmd = new SqlCommand("Select * From tblProductInventory2; SELECT * FROM tblProductCategories", con); con.Open(); using (SqlDataReader rdr = cmd.ExecuteReader()) { ProductsGridView.DataSource = rdr; ProductsGridView.DataBind(); //getting more than one result set using the NextResult method while (rdr.NextResult()) { CategoriesGridView.DataSource = rdr; CategoriesGridView.DataBind(); } } } }
// Event Handlers // ************** private void SelectForm_Load(object sender, System.EventArgs e) { ProductsGridView.ClearSelection(); ProductsGridView.CellClick += new DataGridViewCellEventHandler(ProductsGridView_CellClick); }
protected void BindProductsGrid() { ProductsGridView.DataSource = HccApp.CatalogServices.FindProductsForFile((string)ViewState["id"]); ProductsGridView.DataBind(); }
private void BindGrid() { ProductsGridView.AutoGenerateColumns = false; ProductsGridView.DataSource = DataAccessor.SelectProducts(); ProductsGridView.DataBind(); }
private void RefreshGridView() { ProductsGridView.DataSource = ProductRepository.GetProducts(); ProductsGridView.DataBind(); }