我有一個打開文件對話框,將假設選擇照片並把它保存到數據庫 但問題是,當我訪問上課的時候打開文件對話框的對話框結果是正常 它說,no such table : PhotoFile
當SavePhoto函數調用時使用以下參數:錯誤影像保存到數據庫
TODO(PJ):把值這裏
這是我到目前爲止已經試過
OpenFileDialog d = new OpenFileDialog();
d.Filter = ("JPEG Imange (*.jpg|*.jpg|PNG Image (*.png)|All Files*.*");
if ((d.ShowDialog()) == DialogResult.OK)
{
SavePhoto(txtID.text,d.fileName);
}
下面是該函數的代碼
try {
using (SQLite.SQLiteConnection SQLConnect = new SQLite.SQLiteConnection(g_constring)) {
byte[] photo = FileImageToByte(PhotoFile);
SQLConnect.Open();
if (SQLConnect.State == ConnectionState.Open) {
SQLiteCommand SQLcommand = new SQLiteCommand(SQLConnect);
SQLcommand = SQLConnect.CreateCommand;
SQLcommand.CommandText = "DELETE FROM PhotoFile WHERE PhotoID = '" + PhotoId + "'";
SQLcommand.ExecuteNonQuery();
SQLcommand.Parameters.Clear();
SQLcommand.CommandText = "INSERT INTO PhotoFile(PhotoID, Photo) VALUES(@EmployeeID, @Photo1)";
SQLiteParameter SQLparmID = new SQLiteParameter("@EmployeeID", PhotoId);
SQLparmID.DbType = DbType.String;
SQLparmID.Value = PhotoId;
SQLcommand.Parameters.Add(SQLparmID);
SQLiteParameter SQLparm = new SQLiteParameter("@Photo1", photo);
SQLparm.DbType = DbType.Binary;
SQLparm.Value = photo;
SQLcommand.Parameters.Add(SQLparm);
SQLcommand.ExecuteNonQuery();
bReturn = true;
} else {
bReturn = false;
}
}
} catch (System.Exception eX) {
MessageBox.Show(eX.Message.ToString(), "Error in database", MessageBoxButtons.OK, MessageBoxIcon.Error);
bReturn = false;
}
return bReturn;
}
PhotoFile表在我的數據庫事實上是存在的我已經嘗試了Windows窗體和觸發功能,如果dialog result = ok
,但是當我用openFileDialog
它總是產生錯誤的規定以上。
這與OpenFileDialog有關嗎?看起來像SavePhoto的某些特定參數導致錯誤,而OpenFileDialog本身沒有問題。 – 2012-03-23 16:15:29
你確定問題不在於你的功能嗎?應用程序到底在哪裏破壞? – Lander 2012-03-23 16:16:31
只是想知道爲什麼'SavePhoto()'方法實際上'DELETE FROM' sql查詢? – sll 2012-03-23 16:16:44