Hua Gong retries and study notes, Hua Gong Study Notes

Source: Internet
Author: User

Hua Gong retries and study notes, Hua Gong Study Notes

Today is July 22, March 10, and there are 5 days before the review of the Chinese site. the Retest is performed on the database, and the questions are given by VS and SQL server. difficult. below are my notes for testing the machine.

I. Database Design

Create index <index-name> on <relation-name> (<attribute-list>)

Example: create index dept-index on policuctor (dept_name)

Create view v as <query-expression>

Example: create view faulty

Select ID, name, dept_name

From instructor

Default 0

Check (P) // P is the condition

For example, check (size <10) // only records with a size smaller than 10 can be inserted.

Foreign key (dept_name) references department

On delete cascade

On update cascade

 

SELECT field FROM table WHERE a field Like Condition

 

Condition:

① %: 0 or more characters.

② _: Represents any single character.

③ []: Indicates one of the characters listed in brackets (similar to regular expressions ).

④ [^]: A single character not listed in parentheses.

⑤ When the query content contains wildcards: use [] to enclose special characters.

 

Ii. Database Programming

Server = <IP>; Database = <Database Name>; Integrated Security = false; Uid = <Login Name>; Pwd = <password>

Server = (local); Database = <Database Name>; Integrated Security = sspi

 

 

Public static void ExecuteNoQuery (string SQL)

{

Try

{

SqlCommand cmd = new SqlCommad (SQL, SqlUtil. conn );

If (cmd. ExcuteNoQuery ()> 0)

{

MessageBox. Show ("operation successful ");

}

Else

{

MessageBox. Show ("Operation failed ");

}

}

Catch (Exception ex)

{

MessageBox. Show (ex. Message );

}

 

}

 

 

Public static DataTable ExecuteQuery (string SQL)

{

Try

{

DataTable table = new DataTable ();

DataAdapter adapter = new DataAdapter (SQL, SqlUtil. conn );

Adapter. Fill (table );

Return table;

}

Catch (Exception ex)

{

MessageBox. Show (ex. Message );

Return null;

}

}

 

 

Try

{

SqlConnection conn = new SqlConnection (SqlUtil. connstr );

Conn. Open ();

}

Catch (Exception ex)

{

MessageBox. Show (ex. Message );

Applitcation. Exit ();

Return;

}

 

SqlUtil. conn. Close (); // do not use Dispose () because the connection resources will be recycled.

 

DataGridView1.DataSource = table;

 

SelectedIndexChanged

 

This. dataGridView1.SelectedRows [0]. Cell [0]. Value;

 

DataGridView1.Rows. RemoveAt (maid [0]. index );

 

DataGridView1.SelectionMode = maid mode. FullRowSelect;

 

DataGridView1.ReadOnly = true;

 

DialogResult dr = MessageBox. Show (this, "are you sure you want to delete ?"," Prompt ", MessageBoxButton. YesNO );

If (dr = DialogResult. Yes) // The code after clicking OK

 

Activated

 

Private void refresh ()

{

String SQL = "select * from <Table Name> ";

DataTable table = SqlUtil. ExecuteQuery (SQL );

DataGridView1.DataSource = table;

}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.