Click here to Skip to main content
15,888,521 members
Home / Discussions / C#
   

C#

 
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 
QuestionC# problem passing mine value Pin
classy_dog27-Sep-12 12:13
classy_dog27-Sep-12 12:13 
AnswerRe: C# problem passing mine value Pin
Dave Kreskowiak27-Sep-12 13:35
mveDave Kreskowiak27-Sep-12 13:35 
QuestionC# format date Pin
classy_dog27-Sep-12 6:45
classy_dog27-Sep-12 6:45 
AnswerRe: C# format date Pin
Ravi Bhavnani27-Sep-12 6:49
professionalRavi Bhavnani27-Sep-12 6:49 
AnswerRe: C# format date Pin
Smart Arab27-Sep-12 10:12
Smart Arab27-Sep-12 10:12 
GeneralMy vote of 1 Pin
J4amieC27-Sep-12 21:37
J4amieC27-Sep-12 21:37 
AnswerRe: C# format date Pin
Keith Barrow27-Sep-12 10:44
professionalKeith Barrow27-Sep-12 10:44 
AnswerRe: C# format date Pin
J4amieC27-Sep-12 21:36
J4amieC27-Sep-12 21:36 
AnswerRe: C# format date Pin
KiranKumar Roy14-Oct-12 2:03
KiranKumar Roy14-Oct-12 2:03 
Questionexponential memory Pin
mohammadkaab27-Sep-12 5:06
mohammadkaab27-Sep-12 5:06 
AnswerRe: exponential memory Pin
Pete O'Hanlon27-Sep-12 5:13
mvePete O'Hanlon27-Sep-12 5:13 
GeneralRe: exponential memory Pin
mohammadkaab27-Sep-12 5:49
mohammadkaab27-Sep-12 5:49 
GeneralRe: exponential memory Pin
Dave Kreskowiak27-Sep-12 13:30
mveDave Kreskowiak27-Sep-12 13:30 

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.