zoukankan      html  css  js  c++  java
  • delphi和C# 保存exe文件到数据库

    Delphi:

    procedure TForm1.Button1Click(Sender: TObject);

    var

    strSQL, sfilename: string;

    MStream: TMemoryStream;
    begin
    con1.Connected:=true;
    qry1.sql.clear;
    strsql:='INSERT INTO s_ipadversion(versionno,ipadkhd) VALUES (:no,:upfile )';
    qry1.sql.add(strsql);
    sfilename :='e:Retail.exe';
    MStream := TMemoryStream.Create;
    MStream.LoadFromFile(sfilename);
    qry1.Parameters.ParamByName('no').value:='2019.7.0.8';
    qry1.Parameters.ParamByName('upfile').LoadFromStream(MStream, ftBlob);
    MStream.Free;
    qry1.ExecSQL;
    end;

    ------------------------------------------------------

    C#

    private void button2_Click(object sender, EventArgs e)
    {
    //获取文件名称
    using (OpenFileDialog ofd = new OpenFileDialog())
    {
    ofd.Filter = "文本文件|*.exe";
    if (ofd.ShowDialog() == DialogResult.OK) //如果点击的是打开文件
    {
    string str1 = "2019.9.0.7"; //获取文本框中的数据

    string con = "Server=.;Database=ipadsj;user id=sa;pwd=123456";
    string sql = "insert into s_ipadversion(versionno,ipadkhd) values('" + str1 + "',@khd)";

    SqlConnection mycon = new SqlConnection(con); //这部分与上面的查询操作是一样的
    mycon.Open();
    try //注意写在try-catch语句,要不然估计没法运行=_=
    {
    SqlCommand sqlman = new SqlCommand(sql, mycon); //这里的SqlCommand表示要进行一次数据库的操作
    sqlman.Parameters.AddWithValue("@khd", File.ReadAllBytes(ofd.FileName));
    if (sqlman.ExecuteNonQuery() != 0) //执行数据库语句并返回一个int值(受影响的行数)
    {
    MessageBox.Show("插入数据成功!");
    }
    }
    catch (Exception)
    {
    MessageBox.Show("插入数据错误!");
    }
    }
    }

    }

  • 相关阅读:
    面试题 33 把数组排成最小的数
    面试题32 1的数目
    面试题29 数组中出现次数超过一半的数字
    LeetCode_Combination Sum II
    LeetCode_Combination Sum
    面试题27 二叉搜索树转换为双向链表
    面试题26 复杂链表的复制
    面试题24 二叉搜索树的后序遍历序列
    LeetCode_Binary Tree Inorder Traversal
    省选模拟57 题解
  • 原文地址:https://www.cnblogs.com/linjincheng/p/11642097.html
Copyright © 2011-2022 走看看