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(),"错误提示");
                        }

                    }
                }
            }

  • 相关阅读:
    20199131-2020-3-18 《网络攻防实践》第3周作业
    20199131-第2次作业-网络攻防实践
    20199131-第1次作业-网络攻防概述
    20199131《网络攻防实践》假期作业
    学习《深入理解计算机系统(第三版)》第二章总结
    学习《构建之法(第三版)》第一章总结
    关于宏的使用和Vim及其插件安装的学习总结
    细读《从问题到程序(第二版)》第一章学习总结
    细读《深入理解计算机系统(第三版)》第一章学习总结
    可信计算
  • 原文地址:https://www.cnblogs.com/hyd309/p/1182885.html
Copyright © 2011-2022 走看看