私はC#プログラミングの初心者です。を使用しているときに問題がありFileStream
ます。データベース内の人物のIDを検索して、データベースから写真を取得したい。そしてそれは動作します!!。しかし、その人の写真を2回取得しようとすると(同じIDを2回挿入します)。それは IOException を与えるでしょう
"The process cannot access the file 'C:\Users\dor\Documents\Visual Studio 2010\Projects\studbase\studbase\bin\Debug\foto.jpg' because it is being used by another process."
ボタンが 1 つある --> buttonLoad
| 1 ピクチャーボックス -->pictureBoxPictADUStudent
これはbuttonLoadのコードです
string sql = "SELECT Size,File,Name FROM studgeninfo WHERE NIM = '"+textBoxNIM.Text+"'";
MySqlConnection conn = new MySqlConnection(connectionSQL);
MySqlCommand comm = new MySqlCommand(sql, conn);
if (textBoxNIM.Text != "")
{
conn.Open();
MySqlDataReader data = comm.ExecuteReader();
while (data.Read())
{
int fileSize = data.GetInt32(data.GetOrdinal("size"));
string name = data.GetString(data.GetOrdinal("name"));
using (FileStream fs = new FileStream(name, FileMode.Create, FileAccess.Write))
{
byte[] rawData = new byte[fileSize];
data.GetBytes(data.GetOrdinal("file"), 0, rawData, 0, fileSize);
fs.Write(rawData, 0, fileSize);
fs.Dispose();
pictureBoxPictADUStudent.BackgroundImage = new Bitmap(name);
}
}
conn.Close();
}
else
{
MessageBox.Show("Please Input Student NIM ", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}