zoukankan      html  css  js  c++  java
  • 上传图片、word等文件到数据库


            private void button2_Click(object sender, EventArgs e)
            {
                //OpenFileDialog  opf = new OpenFileDialog();
                if (textBox2.Text == "" || comboBox1.Text  == "" || textBox3.Text == "")
                {
                    MessageBox.Show("请输入完整的信息!", "提示");
                }
                else
                {
                    FileStream fst = new FileStream(textBox2.Text, FileMode.Open, FileAccess.Read);
                    byte[] by = new Byte[fst.Length];
                    fst.Read(by, 0, (int)fst.Length);

                    if (fst.Length == 0)
                    {
                        MessageBox.Show("文件为空!", "提示");
                    }
                    else
                    {
                        

                        try
                        {
                            DataSet ds = new DataSet();
                            sqlDataAdapter2.Fill(ds, "content");
                            DataTable MyTable = ds.Tables[0];
                            DataRow MyRow = MyTable.NewRow();
                            MyRow["ProjectName"] = comboBox1.Text;
                            MyRow["Type"] = textBox4.Text;
                            MyRow["Title"] = textBox3.Text;
                            FileStream fs = new FileStream(textBox2.Text, FileMode.OpenOrCreate, FileAccess.Read);
                            byte[] MyData = new byte[fs.Length];
                            fs.Read(MyData, 0, (int)fs.Length);
                            fs.Close();
                            MyRow["ProjectContent"] = MyData;
                            MyTable.Rows.Add(MyRow);
                            sqlDataAdapter2.Update(ds, "content");
                            ds.AcceptChanges();
                            MessageBox.Show("成功存储!", "提示");
                            sqlDataAdapter2.Dispose();
                            this.Close();
                        }
                        catch(Exception ex)
                        {
                            MessageBox.Show(ex.ToString(),"错误提示");
                        }

                    }
                }
            }

  • 相关阅读:
    推荐几款Vue后台管理系统的框架,以便备用
    vue常用开发ui框架(app,后台管理系统,移动端)及插件
    CSS的flex布局看完这篇你就懂了
    network中的js和xhr
    使用better-scroll插件 点击事件失效
    javaScript -- touch事件详解(touchstart、touchmove和touchend)
    BetterScroll在vue中v-for渲染数据后滚动失效
    布局总结四:利用行高来撑开高度
    git中Please enter a commit message to explain why this merge is necessary.
    Vue中使用Ajax与后台交互
  • 原文地址:https://www.cnblogs.com/hyd309/p/1182885.html
Copyright © 2011-2022 走看看