从数据库中检索BLOB并将其保存在本地

时间:2014-05-10 13:43:22

标签: c# mysql blob store

我正在尝试检索已存储在数据库中的blob。 我想将它本地存储在我的电脑上。我已经走到了这一步,但我现在已经停留了一段时间。任何人都能帮助我实现这一点吗?

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
    }
}

1 个答案:

答案 0 :(得分:0)

请试试这个。

File.WriteAllBytes("filename", tmp); // Requires System.IO