Chinese laborers ' Second interview study notes

Source: Internet
Author: User

Today is March 10, there are 5 days before the second round of the Chinese laborers. The second-round test is the database, with VS and SQL Server to do the problem. It's not very difficult. Here are the notes I'm going to try.

First, the database design

    1. Build Index

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

Example:CREATE index Dept-index on instructor (dept_name)

    1. Create a View

Create View V as <query-expression>

Example:CREATE view faulty as

Select Id,name,dept_name

From instructor

    1. Default value

Default 0

    1. Check constraint

Check (P)//p as Condition

Example Check (size<10)// allow only records with size less than ten to be inserted

    1. cascading deletes and cascading updates

Foreign KEY (dept_name) References Department

ON DELETE Cascade

ON UPDATE cascade

    1. Fuzzy search

SELECT field from table WHERE a field like condition

Conditions :

①% : Represents any of 0 or more characters.

②_ : Represents any single character.

③[] : Represents one of the characters listed in parentheses (similar to a regular expression).

④[^] : Represents a single character that is not listed in parentheses.

⑤ query content contains wildcard characters: use [] to enclose a special character .

Second, the database programming

    1. Connecting database statements

server=<ip>;D atabase=< database name >;integrated security=false; uid=< Login name >; pwd=< password >

server= (local);D atabase=< database name >;integrated Security=sspi

    1. Insert, UPDATE, delete method

public static void Executenoquery (String sql)

{

Try

{

SqlCommand cmd=new Sqlcommad (sql,sqlutil.conn);

if (cmd. Excutenoquery () >0)

{

MessageBox.Show ("successful operation");

}

Else

{

MessageBox.Show ("Operation failed");

}

}

catch (Exception ex)

{

MessageBox.Show (ex. Message);

}

}

    1. Method of Select

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;

}

}

    1. Connect Database methods

Try

{

SqlConnection conn = new SqlConnection (SQLUTIL.CONNSTR);

Conn. Open ();

}

catch (Exception ex)

{

MessageBox.Show (ex. Message);

Applitcation.exit ();

Return

}

    1. To close a database method

SqlUtil.conn.Close (); no Dispose (), because the connection resource is recycled

    1. DataGridView Binding Data Method

Datagridview1.datasource = table;

    1. Drop-down box Change event

SelectedIndexChanged

    1. Get DataGridView The first element of the first row in a selected row

This.datagridview1.selectedrows[0]. Cell[0]. Value;

    1. Delete DataGridView selected first row

DataGridView1.Rows.RemoveAt (Datagridview1.selectedrows[0].index);

    1. Set DataGridView to select only rows ( not cells )

Datagridview1.selectionmode=datagridviewselcitonmode.fullrowselect;

    1. Set DataGridView read-only

Datagridview1.readonly = true;

    1. YesNo Confirmation Box

DialogResult dr = MessageBox.Show (this, "OK delete ?", "hint", messageboxbutton.yesno);

if (dr==dialogresult.yes)// Click OK after the code

    1. Form Reactivation Event ( to refresh the table after the Add and modify windows are closed )

Activated

    1. Refresh Table Window Code

private void Refresh ()

{

String Sql= "select * FROM < table name >";

DataTable table=sqlutil.executequery (SQL);

Datagridview1.datasource = table;

}

Chinese laborers ' Second interview study notes

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.