C # connect the KTV system to the SQL database C # application form,

Source: Internet
Author: User

C # connect the KTV system to the SQL database C # application form,

--- Restore content start ---

Wudaokou Peking University qingbird campus

KTV Project

INSTRUCTOR: Yuan Yuming

SQL database Relationship Diagram

 

Step 1:

 

 

1 private void DoubleClicklvContry () 2 {3 if (this. lvtype. SelectedItems [0]! = Null) 4 {5 this. lvContry. visible = true; 6 this. lvtype. visible = false; 7 type = this. lvtype. selectedItems [0]. tag. toString (); 8 this. lvContry. location = this. lvtype. location; 9 lvContry. dock = DockStyle. fill; 10} 11 string SQL = "select singertype_id, singertype_name, singertype_imageURL from singer_type"; 12 cmd = new SqlCommand (SQL, con. conntion); 13 try 14 {15 con. openConntion (); 16 SqlDataRea Der reader = cmd. ExecuteReader (); 17 if (this. lvContry. Items! = Null) 18 {19 lvSinger. items. clear (); 20} 21 if (reader. hasRows) 22 {23 int index = 0; 24 while (reader. read () 25 {26 ListViewItem item = new ListViewItem (); 27 item. text = reader [1]. toString (); 28 item. tag = reader [0]. toString (); 29 this. imageList2.Images. add (Image. fromFile (@ "E: \ KTV \ SingerTypeIamge \" + reader [2]. toString (); 30 item. imageIndex = index; 31 this. lvContry. items. add (item); 32 in Dex ++; 33} 34} 35 reader. close (); 36} 37 catch (Exception ex) 38 {39 MessageBox. show (ex. message); 40} 41 finally 42 {43 con. closeConntion (); 44} 45} 46 47 48 Part 2: 49 private void lvtype_DoubleClick_1 (object sender, EventArgs e) 50 {51 DoubleClicklvContry (); 52} 53 // <summary> 54 // Add data to lvSinger 55 // </summary> 56 private void DoubleClicklvSinger () 57 {58 if (this. lvContry. selected Items [0]! = Null) 59 {60 this. lvSinger. visible = true; 61 this. lvContry. visible = false; 62 this. lvSinger. location = this. lvContry. location; 63 this. lvSinger. dock = DockStyle. fill; 64 65 string SQL = string. format ("select singer_id, singer_name, singer_photo_url from singer_info where singer_sex = '{0}' and singertype_id = {1}", 66 type, Convert. toInt32 (this. lvContry. selectedItems [0]. tag); 67 cmd = new SqlCommand (sq L, con. conntion); 68 try 69 {70 con. openConntion (); 71 // imageList3.Images. clear (); 72 SqlDataReader reader = cmd. executeReader (); 73 if (this. lvSinger. items! = Null) 74 {75 lvSinger. items. clear (); 76} 77 if (reader. hasRows) 78 {79 int index = 0; 80 while (reader. read () 81 {82 ListViewItem item = new ListViewItem (); 83 item. text = reader [1]. toString (); 84 item. tag = reader [0]. toString (); 85 this. imageList3.Images. add (Image. fromFile (@ "E: \ KTV \ singerPhoto \" + reader [2]. toString (); 86 item. imageIndex = index; 87 this. lvSinger. items. add (item); 88 index ++; 89} 90} 91 reader. close (); 92} 93 catch (Exception ex) 94 {95 MessageBox. show (ex. message); 96} 97 finally {98 con. closeConntion (); 99} 100} 101} 102 103

 

104 Part 3: Find the songs of singers in the region

 1    private void lvContry_DoubleClick(object sender, EventArgs e) 2         { 3             DoubleClicklvSinger(); 4         }        private void DoubleClickSong()  5         { 6             if (this.lvSinger.SelectedItems[0]!=null) 7             { 8                  string sql = string.Format("select song_id,song_name,song_url,singer_name from song_info,singer_info"+ 9                 " where song_info.singer_id=singer_info.singer_id and singer_info.singer_id={0}",Convert.ToInt32(this.lvSinger.SelectedItems[0].Tag));10                  FrmSong fs = new FrmSong();11                  fs.sql = sql;12 13                  fs.Show();14                  this.Hide();15             }

 

 

Part 4: select the artist information database to connect to the workshop

1   private void FrmSong_Load(object sender, EventArgs e)2         {3            4             adapter = new SqlDataAdapter(sql, db.Conntion);5             adapter.Fill(ds, "song_info");6       7             this.dataGridView1.DataSource = ds.Tables["song_info"];8             this.dataGridView1.AutoGenerateColumns = false;

 

 

Upload a miserable list by clicking a song

 

 

Public string Name {get; set;} public string age {get; set;} private void BOFANG_Load (object sender, EventArgs e) {this. listView1.Items. clear (); foreach (Song item in ListSong. list) {ListViewItem lvitem = new ListViewItem (item. songName); lvitem. subItems. add (item. songPath); string sate = item. sate = Sateze. unPaly? "Not played": "played"; lvitem. SubItems. Add (sate); this. listView1.Items. Add (lvitem );

Schematic diagram of playing music

 

 

Part 5: if the DATA form is uploaded to the private void dataGridView1_DoubleClick (object sender, EventArgs e) {if (this. dataGridView1.SelectedRows [0]! = Null) {BOFANG dd = new BOFANG (); Song song = new Song (); song. songName = this. dataGridView1.SelectedRows [0]. cells [3]. value. toString (); song. songPath = this. dataGridView1.SelectedRows [0]. cells [2]. value. toString (); dd. name = song. songName; ListSong. addSong (song); MessageBox. show ("added successfully. Please view it in the clicked song !!! "); Step 6: private void button#click (object sender, EventArgs e) {string en = textBox1.Text; SqlConnection con = new SqlConnection (SQL. str); string SQL = string. format ("select * from song_info where song_ AB like '" + en + "%'"); SqlDataAdapter da = new SqlDataAdapter (SQL, con); DataSet ds = new DataSet (); da. fill (ds, "song_info"); dataGridView1.DataSource = ds. tables ["song_info"]; SqlCommand cmd = ne W SqlCommand (SQL, con); try {con. open (); int count = cmd. executeNonQuery (); if (count> 0) {MessageBox. show ("search successful") ;}} catch (Exception) {MessageBox. show ("network exception Check network or SQL database !!! "); Con. Close ();

 

 

 

 

--- Restore content end ---

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.