Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Saturday, December 3, 2022

Thursday, November 10, 2022

How to delete data in C# from sql database : code in c#

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

namespace WebApplication1
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

 
        protected void Button2_Click(object sender, EventArgs e)
        {
            SqlConnection cnn = new SqlConnection(@"Data Source=localhost\SQLExpress;Initial Catalog=awais;Integrated Security=True;Integrated Security=True ");
            cnn.Open();
            string query = "delete from logout where name = '" +TextBox1.Text+ "';";
            SqlCommand cmd = new SqlCommand(query, cnn);
            cmd.ExecuteNonQuery();

            Response.Write("Deletion  is done!");

        }
    }
}

Friday, November 4, 2022

Friday, November 27, 2015

Up-Date record in SQL Database using C#.net

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

namespace WebApplication1
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            SqlConnection cnn = new SqlConnection(@"Data Source=localhost\SQLExpress;Initial Catalog=awais;Integrated Security=True;Integrated Security=True ");
            cnn.Open();
string query = "update logout set name ='"+TextBox3.Text+"' where name = '" + TextBox2.Text + "';";
            SqlCommand cmd = new SqlCommand(query, cnn);
            cmd.ExecuteNonQuery();

            Response.Write("update  is done!");

        }

   
    }
}


Sunday, November 2, 2014

Create Foreign key in Sql

How To create Foreign key in sql table :

You have a code(for table)like this:

create table person( name     varchar2(5),
                               Id_no       number(3),
                              Address    number(10) );

and you have another table of place:

create table place(name   varchar2(5)primary key,
                             location  varchar2(5),
                             owner_name  varchar2(5) );

Now you want to make owner_name  as Foreign key which relate name of person to the owner name of place table. so there are two methods to make a column foreign key one in table order and other one is column order.
===================================================
Column  Order:
create table place(name              varchar2(5)    primary key,
                             location           varchar2(5),
                             owner_name   varchar2(5)   references   person(name) );
==================================================
Table Order:
create table place(name              varchar2(5)   primary key,
                             location           varchar2(5),
                             owner_name   varchar2(5),
                            constraint   n_pk    foreign key (owner_name)  references   person(name) );

Note:All the bold words are reserved word in Sql.

See Also :How to create Primary Key in data base table using Sql Command.


Create Primary Key in Sql table

How To create primary key in sql table :

You have a code(for table)like this:

create table person( name     varchar2(5),
                               Id_no       number(3),
                              Address    number(10));

Now you want to make Id_no as Primary key: so there are two methods to make a column primary key one in table order and other one is column order.
===================================================
Column  Order:
create table person( name    varchar2(5),
                               Id_no     number(3) primary key,
                              Address  number(10));
==================================================
Table Order:
create table person( name varchar2(5),
                               Id_no number(3),
                              Address number(10),
                             primary key(Id_no));

Create Table in Sql

How to create table in sql:-

The create table statement is used to create a new table.
Example:
create table employee
(first varchar(15),
 last varchar(20),
 age number(3),
 address varchar(30),
 city varchar(20),
 state varchar(20));
 
To create a new table, enter the keywords create table followed by the table name, followed by an open parenthesis, followed by the first column name, followed by the data type for that column, followed by any optional constraints, and followed by a closing parenthesis. It is important to make sure you use an open parenthesis before the beginning table, and a closing parenthesis after the end of the last column definition. Make sure you seperate each column definition with a comma. All SQL statements should end with a ";".

Here are the most common Data types:
char(size)Fixed-length character string. Size is specified in parenthesis. Max 255 bytes.
varchar(size)Variable-length character string. Max size is specified in parenthesis.
number(size)Number value with a max number of column digits specified in parenthesis.
dateDate value
number(size,d)Number value with a maximum number of digits of "size" total, with a maximum number of "d" digits to the right of the decimal.


See Also:   How To Create Primary Key in Sql table


See Also:  How to create Foreign Key Using Sql Command