Jump to content

cd database

- - - - -

  • Please log in to reply
No replies to this topic

#1
mimi84

mimi84

    Newbie

  • Members
  • Pip
  • 1 posts
hello there, how are you. I saw ur web address on facebook. pls I need help.. am doin my final yr project for my undergraduate degree.struggled quite a lot but have been able to get most of the work done. i just have a few tidy ups now.

my project is CD Database. A cd is put into the cd drive and the software i develop should copy all the cd information (like the artist, album , genre, etc) and then transfer to an access database. I've written the code in C#.
the problem am havin now is that i dont want the program to crash if the user suddenly decides to delete the database. I dont know how to do this. am feelin lost . pls help.

i really will appreciate it. any other thing u can add to enhance it will also be well appreciated.






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(

                    "ReleaseDateYear").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)

        {


        }

            

    }

}







1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users