首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

C# 存取資料庫圖像實戰(三)

     編輯:關於C語言

移除圖片功能

private void buttonMoveImage_Click(object sender, EventArgs e)
{
    // 以空白 Unicode 位元組陣列覆蓋原圖像欄位
    byte[] bytes = System.Text.Encoding.Unicode.GetBytes("");
    dataset.Tables[0].Rows[listBox1.SelectedIndex][1] = bytes;
    ShowImage(); // 重新整理顯示
}

儲存變更

private void buttonSave_Click(object sender, EventArgs e)
{
    adapter.Update(dataset, "pub_info");
    MessageBox.Show("儲存成功");
}

列表選項切換事件

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    ShowImage();
    // 同步 BindingContext 位置,確保文字方塊顯示對應資料
    this.BindingContext[dataset, "pub_info"].Position = listBox1.SelectedIndex;
}

執行效果

程式可即時更換圖片、清除圖片,並支援直接編輯文字欄位,最後透過 DataAdapter.Update() 將所有異動寫回資料庫。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved