using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Threading;
using WMPLib;
using AxWMPLib;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
namespace CdRomMediaChangedEvent
{
public partial class Form1 : Form
public Form1()
InitializeComponent();
}
private void axWindowsMediaPlayer1_CdromMediaChange(object sender, _WMPOCXEvents_CdromMediaChangeEvent e)
try
// For Media Player to get the cd rom drive to play the cd from.
IWMPPlaylist Media = axWindowsMediaPlayer1.cdromCollection.Item(e.cdromNum).Playlist;
axWindowsMediaPlayer1.URL = Media.get_Item(e.cdromNum).sourceURL; // plays song
IWMPPlaylist songs = Media; // Put media info into new object songs
int songCount = songs.count; //
for (int j = 0; j < songCount; j++)
int songNo = (j + 1);
string textBox1Text = songs.name;
string textBox2Text = songNo.ToString();
string textBox3Text = songs.get_Item(j).getItemInfo(
"Name");
string textBox4Text = songs.get_Item(j).getItemInfo(
"author");
string textBox5Text = songs.get_Item(j).getItemInfo(
"Title");
string textBox6Text = songs.get_Item(j).getItemInfo(
"Album");
string textBox7Text = songs.get_Item(j).getItemInfo(
"copyright");
string textBox8Text = songs.get_Item(j).getItemInfo(
"Artist");
string textBox9Text = songs.get_Item(j).getItemInfo(
"Genre");
string textBox10Text = songs.get_Item(j).getItemInfo(
"Bitrate");
string textBox11Text = songs.get_Item(j).getItemInfo(
"WM/Year").ToString();
string textBox12Text = songs.get_Item(j).getItemInfo(
"duration");
string connectstring, statement1;
OleDbConnection connect = new OleDbConnection();
DataSet EasyDS = new DataSet();
OleDbDataAdapter adapterOledb;
statement1 = "Select * From Customer";
string db = @"C:\CdRomMediaChangedEvent1\CdRomMediaChangedEvent\musicCDdb.mdb;";
connectstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + db;
connect.ConnectionString = connectstring;
adapterOledb = new OleDbDataAdapter(statement1, connect);
OleDbCommand myCommand = new OleDbCommand("Insert into Customer(CDROMName, SongNumber, Name, Author, Title, Album, Copyright, Artist, Genre, Bitrate, YearOfSong, Duration) values('" + textBox1Text + "','" + textBox2Text + "','" + textBox3Text + "','" + textBox4Text + "','" + textBox5Text + "','" + textBox6Text + "','" + textBox7Text + "','" + textBox8Text + "','" + textBox9Text + "','" + textBox10Text + "','" + textBox11Text + "','" + textBox12Text + "')", connect);
connect.Open();
myCommand.ExecuteNonQuery();
connect.Close();
adapterOledb.Fill(EasyDS, "Customer");
dataGridView1.DataSource = EasyDS;
dataGridView1.DataMember = "Customer";
catch (Exception)
MessageBox.Show("Please Insert a CD");
private void button1_Click_1(object sender, EventArgs e)
label6.ResetText();
string WhereClause;
// If they only entered a category, go to that category
if (string.IsNullOrEmpty(textBox1.Text) && string.IsNullOrEmpty(textBox2.Text) && string.IsNullOrEmpty(textBox3.Text) && string.IsNullOrEmpty(textBox4.Text) && string.IsNullOrEmpty(textBox5.Text))
label6.Text = "You didn't enter any search " + "parameters. Try again.";
return;
WhereClause = "Where ";
if (string.IsNullOrEmpty(textBox1.Text))
WhereClause = WhereClause + "InStr(Title,'" + textBox1.Text + "')>0 AND ";
if (string.IsNullOrEmpty(textBox2.Text))
WhereClause = WhereClause + "InStr(Name,'" + textBox2.Text + "')>0 AND ";
if (string.IsNullOrEmpty(textBox3.Text))
WhereClause = WhereClause + "InStr(Album,'" + textBox3.Text + "')>0 AND ";
if (string.IsNullOrEmpty(textBox4.Text))
WhereClause = WhereClause + "InStr(Artist,'" + textBox4.Text + "')>0 AND ";
if (string.IsNullOrEmpty(textBox5.Text))
WhereClause = WhereClause + "InStr(YearOfSong,'" + textBox5.Text + "')>0 AND ";
if (Strings.Right(WhereClause, 4) == "AND ")
WhereClause = Strings.Left(WhereClause, Strings.Len(WhereClause) - 4);
DataSet EasyDS2 = new DataSet();
statement1 = "Select * From Customer " + WhereClause;
OleDbDataAdapter adapterOledb = new OleDbDataAdapter(statement1, connect);
adapterOledb.Fill(EasyDS2, "Customer");
dataGridView1.DataSource = EasyDS2;
dataGridView1.Refresh();
private void Form1_Load(object sender, EventArgs e)
Attachment: CdRomMediaChangedEvent1.zip