Click here to Skip to main content
15,905,877 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
am a new programmer, doin my final year project. I am to develop a CD database. The software developed should extract the details of an audio CD ( like album name, artist, genre, year released) and then transfer them to a database. I am using an access database.

so far i hv been able to get the attributes except the year. Also how do I prevent duplicate copies of cd data like the album, artist, etc.
pls help,only hv 2days left to deadline.


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;      
                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");
                    dataGrid1.DataSource = EasyDS;
                    dataGrid1.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 the category page 
            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);
            }
            string connectstring, statement1;
            OleDbConnection connect = new OleDbConnection();
            DataSet EasyDS2 = new DataSet();
            statement1 = "Select * From Customer " + WhereClause;
            string db = @"C:\CdRomMediaChangedEvent1\CdRomMediaChangedEvent\musicCDdb.mdb;";
            connectstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + db;
            connect.ConnectionString = connectstring;
            OleDbDataAdapter adapterOledb = new OleDbDataAdapter(statement1, connect);
            adapterOledb.Fill(EasyDS2, "Customer");
            dataGrid1.DataSource = EasyDS2;
            dataGrid1.DataMember = "Customer";
            dataGrid1.Refresh();
           }
        private void Form1_Load(object sender, EventArgs e)
        {
        }
      
            
    }
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900