Introduction to ASP.NET

ASP.NET is a technology under .NET Framework which is used to create web sites.
ASP stands for Active Server Pages.

HTML, CSS and javascript are used as basic building blocks for developing websites using ASP.NET.

C#.NET will act as a code behind language along with ASP.NET to implement the functional logic of websites.

Monday, 28 November 2016
Posted by Sudhir Chekuri
Tag :

SQL Injection

Hacking database by entering input data which maninpulates sql queries is

known as sql injection.

Example:

Expected: select * from tbl_data where name='admin' and pwd='password'
Hacked: select * from tbl_data where name='admin' and pwd=' or 'a'='a'

With sql injection attacker may overwrite or delete data in database, can make app to behave in a different way.


SQL injection can be done using post and get parameters, cookie values, form fields and header values.

Parmeterized sql queries will help in controlling sql injection.

In .NET - > ADO.NET -> SQL queries using parameters(@name) to append values in query is recommended.


Input client side validations will also mitigate sql injection issues.

stored procedures will reduce sql injection.


Sunday, 27 November 2016
Posted by Sudhir Chekuri

C#.NET ref and out parameters with example

ref stands for reference and out stands for output.

ref parameter variable should be initialized before we call the method. That value will be used a as reference value in the method.

out parameter variable initialization is not required but it should be returned by the method.

Example program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FirstConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Program p = new Program();
            //val1 has to be initialized
            int val1 = 10;
            p.Add(ref val1);
            //val2 initialization not required
            int val2;
            int j = p.Sub(out val2);
            Console.WriteLine(j);
            Console.ReadKey();

        }

        public void Add(ref int val1)
        {            //code goes here
            Console.WriteLine("Hello");
        }
        public int Sub(out int val2)
        {
//val2 is changed from 2 to 5
            val2 = 5;
            return val2;
        }
    }
}

Output:
Hello
5


Tuesday, 31 May 2016
Posted by Sudhir Chekuri

Stored Procedures in ADO.NET

// 1. create a command object identifying
        // the stored procedure
        SqlCommand cmd  = new SqlCommand(
               "CustOrderHist", conn);
 
        // 2. set the command object so it knows
        // to execute a stored procedure
        cmd.CommandType = CommandType.StoredProcedure;
 
        // 3. add parameter to command, which
        // will be passed to the stored procedure
        cmd.Parameters.Add(
               new SqlParameter("@CustomerID", custId));



Saturday, 12 March 2016
Posted by Sudhir Chekuri
Tag :

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

        }


Posted by Sudhir Chekuri
Tag :

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

        }


Posted by Sudhir Chekuri
Tag :

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");
            //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");
         

        }



Posted by Sudhir Chekuri
Tag :

Followers

Total Pageviews

Powered by Blogger.

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