Click here to Skip to main content
15,916,941 members
Home / Discussions / C#
   

C#

 
GeneralRe: Visual Studio 10 Naming Issue? Pin
PDTUM3-Oct-12 5:25
PDTUM3-Oct-12 5:25 
GeneralRe: Visual Studio 10 Naming Issue? Pin
Smart Arab3-Oct-12 7:01
Smart Arab3-Oct-12 7:01 
QuestionC# database error Pin
classy_dog28-Sep-12 6:50
classy_dog28-Sep-12 6:50 
AnswerRe: C# database error Pin
Matt U.28-Sep-12 6:59
Matt U.28-Sep-12 6:59 
AnswerRe: C# database error Pin
Emmanuel Medina28-Sep-12 9:40
professionalEmmanuel Medina28-Sep-12 9:40 
QuestionImage compression Pin
hardiksince198728-Sep-12 6:13
hardiksince198728-Sep-12 6:13 
AnswerRe: Image compression Pin
Ravi Bhavnani28-Sep-12 6:15
professionalRavi Bhavnani28-Sep-12 6:15 
AnswerRe: Image compression Pin
Abhinav S28-Sep-12 17:00
Abhinav S28-Sep-12 17:00 
Questiongeneric queue synchronisation Pin
Ramu katturi28-Sep-12 3:18
Ramu katturi28-Sep-12 3:18 
AnswerRe: generic queue synchronisation Pin
Dave Kreskowiak28-Sep-12 3:58
mveDave Kreskowiak28-Sep-12 3:58 
Questionupdate in LINQ to SQL is not working for C#.Net? Pin
Jineesh TR27-Sep-12 23:26
professionalJineesh TR27-Sep-12 23:26 
AnswerRe: update in LINQ to SQL is not working for C#.Net? Pin
J4amieC28-Sep-12 0:09
J4amieC28-Sep-12 0:09 
GeneralRe: update in LINQ to SQL is not working for C#.Net? Pin
Jineesh TR28-Sep-12 0:18
professionalJineesh TR28-Sep-12 0:18 
GeneralRe: update in LINQ to SQL is not working for C#.Net? Pin
Dave Kreskowiak28-Sep-12 1:22
mveDave Kreskowiak28-Sep-12 1:22 
GeneralRe: update in LINQ to SQL is not working for C#.Net? Pin
Jineesh TR30-Sep-12 19:44
professionalJineesh TR30-Sep-12 19:44 
GeneralRe: update in LINQ to SQL is not working for C#.Net? Pin
Dave Kreskowiak1-Oct-12 2:05
mveDave Kreskowiak1-Oct-12 2:05 
GeneralRe: update in LINQ to SQL is not working for C#.Net? Pin
anglesen11202-Oct-12 18:23
anglesen11202-Oct-12 18:23 
AnswerRe: update in LINQ to SQL is not working for C#.Net? Pin
Emmanuel Medina28-Sep-12 9:48
professionalEmmanuel Medina28-Sep-12 9:48 
GeneralRe: update in LINQ to SQL is not working for C#.Net? Pin
Jineesh TR30-Sep-12 19:41
professionalJineesh TR30-Sep-12 19:41 
Questionupload a song into database... Pin
sri apple27-Sep-12 21:37
sri apple27-Sep-12 21:37 
AnswerRe: upload a song into database... Pin
Smart Arab27-Sep-12 22:13
Smart Arab27-Sep-12 22:13 
1-Create database with table : tbSongs
guid | songname | songfile
----------------------------
guid uniuqeidentfieir
songname varchar(255)
songfile image

2-Convert your song to byte array
C#
public static byte [] File2ByteArray (string szFileName)
	{
		Stream st = new FileStream (szFileName,FileMode.Open);
		byte[] bit = new byte[st.Length];
		st.Read(bit, 0 , (int)st.Length);
		st.Close();
		return bit;
	}


3-Store it in tbSongs
C#
#region Fields

private Guid _guid;
public Guid guid
{
    get
    {
        return _guid;
    }
    set
    {
        _guid = value;
    }
}
private string _songname;
public string songname
{
    get
    {
        return _songname;
    }
    set
    {
        _songname = value;
    }
}
private Byte[] _song;
public Byte[] song
{
    get
    {
        return _song;
    }
    set
    {
        _song = value;
    }
}

#endregion

#region Database
public void Insert()
{
    DBConnect.DBCommand.CommandText = "INSERT INTO tbSongs VALUES (?, ?, ?)";

    DBConnect.DBCommand.Parameters.AddWithValue("@guid", guid);
    DBConnect.DBCommand.Parameters.AddWithValue("@songname", songname);
    DBConnect.DBCommand.Parameters.AddWithValue("@image", song);

    DBConnect.DBCommand.ExecuteNonQuery();
    DBConnect.DBCommand.Parameters.Clear();
}


to retrive the song from database :
Find you song with guid or name and cast datareader to bytes array.
C#
public static byte[] GetFilebytes(guid guid)
{
    DBCommand = new DBCommand("SELECT songfile FROM tbsongs WHERE guid = @guid", DataBase.DBConnection);
    DBCommand.Parameters.AddWithValue("@guid", guid);
    byte[] filebytes = (byte[])DBCommand.ExecuteScalar();
    DataBase.DBCommand.Parameters.Clear();
    return filebytes;
}


4-Use File Stream or Memory Stream to Save your Song
C#
byte[] filebites = GetFilebytes(songguid)
           FileStream fs = new FileStream("c:\\mysong.mp3", FileMode.CreateNew, FileAccess.Write);
           BinaryWriter bw = new BinaryWriter(fs);
           bw.Write(filebytes);
           bw.Close();
           fs.Close();


Hope this help
AnswerRe: upload a song into database... Pin
Abhinav S27-Sep-12 22:25
Abhinav S27-Sep-12 22:25 
QuestionRead Emails Pin
Kevin Marois27-Sep-12 12:59
professionalKevin Marois27-Sep-12 12:59 
AnswerRe: Read Emails Pin
Sarath C27-Sep-12 20:22
Sarath C27-Sep-12 20:22 
AnswerRe: Read Emails Pin
Ravi Bhavnani28-Sep-12 6:12
professionalRavi Bhavnani28-Sep-12 6:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.