Showing posts with label Coding. Show all posts
Showing posts with label Coding. Show all posts

SQL Quick Guide

SQL is standard language for access databases. SQL (Structured Query Language) is use for storing, manipulating and retrieving data from database. There are many relational database management system that use SQL as standard database system. For example: MySQL, SQL Server,  MS Access, Oracle, etc.

Tables

A table is composed of records and fields that hold data. All data in one table having relation as the table name. Tables are called datasheets too.

Records

A record is composed of fields. One record is contain different fields that have the same ID. Records are also called row.

Fields

A Field is composed of one data. A Field is the intersection between a row and a column. If you have 2 rows and 2 columns, then you have 4 fields.

Some common syntax of SQL:

SQL Select:
SELECT column_1, column_2, ...column_n
FROM table_name;
SQL Insert:
INSERT INTO  table_name ( column_1, column_2, ...column_n )
VALUES ( value_1, value_2, ...value_n );
SQL Update:
UPDATE table_name SET
column_1 = value_1, column_2 = value_2, column_n = value_n
WHERE column = value;
SQL Delete:
DELETE FROM table_name
WHERE column = value;

SQL Where:
WHERE column= value;
SQL Order By:
ORDER BY column { ASC | DESC };
SQL Create Table:
CREATE TABLE table_name {
column_1 datatype (size),
column_2 datatype (size);
column_n datatype (size);
PRIMARY KEY (one or more columns);
}
SQL Drop Table:
DROP table_name;
SQL Alter Table:
ALTER TABLE table_name { ADD | MODIFY | DROP } column { datatype };
SQL Create Database:
CREATE DATABASE database_name;
SQL Drop Database:
DROP DATABASE database_name;



How To Use Bootstrap



What is Bootstrap?
Bootstrap is a free front-end framework that includes typography, form, tables, navigation, image design and many other. This framework is easily to use and very useful to make responsive webdesign. Responsive webdesign is a web which automatically adjust their size and performance on all device, so it can be looks good in mobile size until desktop size.

Where to get bootstrap?
You can get bootstrap from:
- open source (bootstrap CDN)
What you need is just to include this jquery below to host a bootstrap from a CDN (Content Delivery Network)


 <!-- CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<!-- JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

- download bootstrap
You can download bootstrap and host it by yourself. Go to getbootstrap.com to get the latest version of bootstrap.

Create a Webpage Using Bootstrap

There are three things that you need to know in making a webpage using bootstrap:

1. Add HTML5 doctype
 Bootstrap is using HTML5 for all webpage. So, you need to add HTML5 doctype:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
  </head>
</html>

 2. Add meta tag for mobile responsive
 Bootstrap is support for mobile responsive that called bootstrap3. Add this meta tag in head element to ensure touch zooming and proper rendering:

 <meta name="viewport" content="width=device-width, initial-scale=1">

3. Choose containers
There are two type of basic containers in bootstrap:

- .container: this class provides a responsive fixed container
- .container-fluid: this class provides a full width container

Example of Bootstrap Page
This is a very simple example of webpage that using bootstrap, we hope this can help you get any idea about how to use bootstrap.

 <!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h1>Bootstrap Page Example</h1>
  <p>Here is some text that you can put.</p>
</div>

</body>
</html>



How To Make a Connection Database SQL Server Using C# Based Web

We make a connection into database before we can insert, update, or deleting a query in table. After all, this is the first step to make any change in our database. Before we make a connection code, you must already have the database and its table (we will teach you how to make it later in different post). You need to a web application, if you want to make insert or update code later.

So, if you already have it all, go into code behind and check if your .aspx.cs file has this code on its top:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;

Sure, we need data sql client to make a connection into database. If you already has this all code, add connection variables in your public class, like this:

private string connection = WebConfigurationManager.ConnectionStrings["Database"].ConnectionString;

Change the word "Database", as your database name in your web.configuration.
Then create an event for one of your button, so you can insert a query into your database.

protected void btn_Click(object sender, EventArgs e)
{
}

Change the word btn as your button ID. Now, insert all of codes below in the parenthesis of btn_Click
First, you can INSERT/ UPDATE/ DELETE for SQL variables, here we give the example of INSERT code:

string SQL = "INSERT INTO t_mahasiswa (column1,column2) VALUES ('" + txtBox1.Text + "','" + txtBox2.Text + "')";

Change the word column1 and column2 as your table column name, you can the column too as you wish.
Change the word txtBox1 and txtBox2 as your textBox name that you want its value to be inserted into database.

Then add connection and insert code to make a connection into database

SqlConnection conn = new SqlConnection(connection);
SqlCommand comm = new SqlCommand(SQL, conn);

To make all of codes above work, you need to add a trigger,

try
{
conn.Open();
comm.ExecuteNonQuery();

txtBox1.Text = "";
txtBox2.Text = "";
}
catch (Exception)
{
throw;
}
finally
{
conn.Close();
}

Don't forget to change the word txtBox1 and txtBox2 as your txtBox name.