using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.Sql; using System.Data.SqlClient; using System.IO; namespace ImageToDB { public partial class UserEdit : Form { public UserEdit() { InitializeComponent(); } private void UserEdit_Load(object sender, EventArgs e) { LoadNextUser(); } string strConn = "Data Source=wangyang//SQLEXPRESS;Initial Catalog=test;Persist Security Info=True;User ID=uap;Password=uap"; string strGetTopOne = "select top 1 * from users "; /// <summary> /// 保存按鈕事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { if (txtUserID.Text == "" || txtUserID.Text == string.Empty) { //新增 if (txtUserName.Text == "" || txtImagePath.Text == "") { MessageBox.Show("用戶名和圖片不能爲空!"); return; } //這裏看如何將圖片保存到數據庫的。 FileStream fs = File.OpenRead(txtImagePath.Text); byte[] imageb = new byte[fs.Length]; fs.Read(imageb, 0, imageb.Length); fs.Close(); string strSQL = "insert into Users(UserName,UserImage)values(@UserName,@UserImage)"; SqlConnection con = new SqlConnection(strConn); SqlCommand com3 = new SqlCommand(strSQL, con); com3.Parameters.Add("@UserName", SqlDbType.VarChar).Value = txtUserName.Text; com3.Parameters.Add("@UserImage", SqlDbType.Image).Value = imageb; if (com3.Connection.State == ConnectionState.Closed) com3.Connection.Open(); try { com3.ExecuteNonQuery(); MessageBox.Show("新增用戶成功!"); } catch { MessageBox.Show("新增用戶失敗!"); } finally { com3.Connection.Close(); } } else { //修改 //這裏看如何將圖片保存到數據庫的。 string strSQL = "update users set username=@UserName"; if (txtImagePath.Text != "") strSQL += ",userimage=@UserImage"; SqlConnection con = new SqlConnection(strConn); SqlCommand com3 = new SqlCommand(strSQL, con); com3.Parameters.Add("@UserName", SqlDbType.VarChar).Value = txtUserName.Text; if (txtImagePath.Text != "") { FileStream fs = File.OpenRead(txtImagePath.Text); byte[] imageb = new byte[fs.Length]; fs.Read(imageb, 0, imageb.Length); fs.Close(); com3.Parameters.Add("@UserImage", SqlDbType.Image).Value = imageb; } if (com3.Connection.State == ConnectionState.Closed) com3.Connection.Open(); try { com3.ExecuteNonQuery(); MessageBox.Show("修改用戶成功!"); } catch { MessageBox.Show("修改用戶失敗!"); } finally { com3.Connection.Close(); } } } /// <summary> /// 下一位。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button4_Click(object sender, EventArgs e) { string preUserID = txtUserID.Text; LoadNextUser(); if (txtUserID.Text == preUserID) MessageBox.Show("已經是最後一位用戶!"); } /// <summary> /// 清空。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { txtUserID.Text = ""; txtUserName.Text = ""; txtImagePath.Text = ""; pictureBox1.Image = null; } /// <summary> /// 選擇圖片。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btOpenImage_Click(object sender, EventArgs e) { openFileDialog1.Filter = "JPEG|*.jpg|GIF|*.gif"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { txtImagePath.Text = openFileDialog1.FileName; FileStream fs = File.OpenRead(txtImagePath.Text); byte[] imageb = new byte[fs.Length]; fs.Read(imageb, 0, imageb.Length); fs.Close(); MemoryStream memStream = new MemoryStream(imageb); try { Bitmap myimge = new Bitmap(memStream); this.pictureBox1.Image = myimge; } catch { } } } /// <summary> /// 從數據庫中讀取下一位用戶的信息。如果參數爲空則讀取第一條信息。 /// </summary> /// <param name="PreUserID"></param> /// <returns></returns> public DataTable GetTopOneUser(string filter) { strGetTopOne = "select top 1 * from users "; if (filter != "" && filter != string.Empty) strGetTopOne += filter; SqlConnection con = new SqlConnection(strConn); SqlCommand com = new SqlCommand(strGetTopOne, con); if (con.State == ConnectionState.Closed) con.Open(); SqlDataAdapter da = new SqlDataAdapter(com); DataSet ds = new DataSet(); da.Fill(ds, "UserTable"); if (ds != null && ds.Tables.Count > 0) return ds.Tables[0]; else return null; } /// <summary> /// 加載下一位用戶信息 /// </summary> public void LoadNextUser() { //這裏看如何將數據庫圖片讀出來 string filter =""; if (txtUserID.Text != "") filter = " where userid>" + txtUserID.Text; DataTable dt = GetTopOneUser(filter); if (dt.Rows.Count == 0) return; DataRow dr = dt.Rows[0]; txtUserID.Text = dr["UserID"].ToString(); txtUserName.Text = dr["UserName"].ToString(); byte[] imageb = (byte[])dr["UserImage"]; MemoryStream memStream = new MemoryStream(imageb); try { Bitmap myimge = new Bitmap(memStream); this.pictureBox1.Image = myimge; } catch { } } /// <summary> /// 加載上一位用戶信息 /// </summary> public void LoadPreUser() { string filter = ""; if (txtUserID.Text != "") filter = " where userid<" + txtUserID.Text+" order by Userid desc"; DataTable dt = GetTopOneUser(filter); if (dt.Rows.Count == 0) return; DataRow dr = dt.Rows[0]; txtUserID.Text = dr["UserID"].ToString(); txtUserName.Text = dr["UserName"].ToString(); byte[] imageb = (byte[])dr["UserImage"]; MemoryStream memStream = new MemoryStream(imageb); try { Bitmap myimge = new Bitmap(memStream); this.pictureBox1.Image = myimge; } catch { } } /// <summary> /// 關閉。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button3_Click(object sender, EventArgs e) { this.Close(); } /// <summary> /// 上一位 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button5_Click(object sender, EventArgs e) { string preUserID = txtUserID.Text; LoadPreUser(); if (txtUserID.Text == preUserID) MessageBox.Show("已經是最前一位用戶!"); } /// <summary> /// 幫助。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { help helper = new help(); helper.Show(); } } }
界面如下:
背景 今天在使用redis做分佈式緩存提供自增id的時候,發現了�� t Goods_key_37的亂碼問題;因爲存的是Long,然後我就自定義了一個RedisTemplate<string,long>的實例來使用 解決過程 1.剛開始說
本文分享自華爲雲社區《10分鐘搞懂各種內存溢出案例!!(含完整源碼,建議收藏)》,作者:冰 河。 作爲程序員,多多少少都會遇到一些內存溢出的場景,如果你還沒遇到,說明你工作的年限可能比較短,或者你根本就是個假程序員!哈哈,開個玩笑。今天,我
Ai technology 前言 AppBuilder上線了低代碼製作組件功能,可以通過工作流的方式構建自定義組件,完成簡單Agent無法完成的複雜功能,使得生成的文本更加定製化,
最近在刷一些問題的時候看到有下面一個問題 上面問的是當輸入的字符串爲什麼的時候返回 True 總結 在做題目的時候,第一次還做錯了。 這是因爲解答這個題目的時間只有 3 分鐘,沒有自己看題目 後來拿着程序跑了下。 p
var obj = {} var texts = 'hello' let ipt = document.querySelector('#input') let txt = document.querySelector(
前端面試題 - vue的雙向綁定原理是什麼? vue2的雙向數據綁定是通過數據劫持結合發佈者訂閱者模式的方式來實現。 通過object.defineProperty來劫持各個屬性的setter,getter,在數據變化時發佈消息給訂閱者,
原方法 /** * 動態更新form * @param form */ updateForm(form) { this.form.manholeId = form.manholeId; this.form
前端面試題 - null是原始類型,但爲什麼typeof null的結果是object? 造成這個結果的原因是null的內存地址是以000開頭,而js會將000開頭的內存地址視爲object。 通過isNull()來判斷一個值是不是null
前端面試題 - 賦值/淺拷貝/深拷貝的區別?如何實現一個深拷貝? 賦值是拷貝的對象指針,整個對象都是共用的。 淺拷貝是拷貝一層,對象的內容仍是共用的,Object.assign(),拓展運算符都是淺拷貝。 深拷貝是遞歸拷貝深層次,JSON
1)編碼 消息長度(short int-->2個字節) + 消息編號(short int--》2個字節) + 消息體 2)Protobuf協議文檔 (1)syntax="proto3"; (2)命名格式
在Vue中,style scope是一個特性,它可以防止組件的樣式影響到其他組件,從而減少樣式衝突。這個特性通過在生成的CSS選擇器中自動添加一個屬性(通常是data-v-hash)來實現。 如果你遇到了style scope導致樣式無法被
DevExtreme擁有高性能的HTML5 / JavaScript小部件集合,使您可以利用現代Web開發堆棧(包括React,Angular,ASP.NET Core,jQuery,Knockout等)構建交互式的Web應用程序。從Ang
一.Vue文件內容 <template> </template> <script> </script> <style> </style>
CSDN應該是大家接觸到最多的博客平臺了,所以一款能夠發佈到CSDN的自動化工具還是非常有必要的。 今天給大家講講自動化CSDN博客發佈的思路和一些問題的解決辦法。 解決問題的思路一定是最重要的,知識是死的,問題是活的,如何在工作中解決遇
本文分享自華爲雲社區《6個實例帶你解讀TinyVue 組件庫跨框架技術》,作者: 華爲雲社區精選。 在DTSE Tech Talk 《 手把手教你實現mini版TinyVue組件庫 》的主題直播中,華爲雲前端開發DTSE技術佈道師阿健老師給