0

I am trying to retrieve a blob that i have stored in the database. I would then like to store it locally on my pc. ive got this far, but i`m stuck for some time now. can anybody helpt me realise this?

private void button1_Click(object sender, EventArgs e)
{
    string myConnection = "datasource=localhost;port=3306;username=root;password=";
    MySqlConnection myConn = new MySqlConnection(myConnection);
    //                                                                          
    MySqlCommand SelectCommand = new MySqlCommand("select template from csharp.members where username='" + 
        this.user_txt.Text + "' and password = '" + 
        this.password_txt.Text + "' ; ", myConn);
    MySqlDataReader myReader;
    myConn.Open();
    myReader = SelectCommand.ExecuteReader();
    int count = 0;
    while (myReader.Read())
    {
        count = count + 1;
    }
    if (count == 1)
    {
        byte[] tmp = (byte[])(myReader["template"]); // need to save this locally
    }
}
gunr2171
  • 16,104
  • 25
  • 61
  • 88
  • 1
    So apart from the SQL injection attack vulnerability, what's wrong with the code you've got? Have you managed to fetch the byte correctly? Are you *actually* just asking how you can save a byte array to disk? – Jon Skeet May 10 '14 at 13:45
  • Sorry, couldn't resist the urge: http://bobby-tables.com/ – Machinarius May 10 '14 at 13:49
  • possible duplicate of [Write bytes to file](http://stackoverflow.com/questions/6397235/write-bytes-to-file) – nobody May 10 '14 at 13:58

1 Answers1

0

Please try this.

File.WriteAllBytes("filename", tmp); // Requires System.IO
qamar
  • 1,437
  • 1
  • 9
  • 12