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("插入数据错误!");
}
}
}
}