0

我在数据库中创建了一个名为 Workflows 的表,其中包含名为 document 的二进制字段,如何将文档上传到该字段以供以后使用....

OpenFileDialog ofd = new OpenFileDialog();
RapidWorkflowDataContext context = new RapidWorkflowDataContext();
private void buttonOpen_Click(object sender, EventArgs e)
{
    if (ofd.ShowDialog() == DialogResult.OK && ofd.FileName.Length > 0)
    {

    }
}
4

1 回答 1

0

Without knowing the schema of your Workflows table, it would be something like this:

Stream myStream = openFileDialog1.OpenFile();
if (myStream != null)
{
    using (myStream)
    {
        Workflows w = new Workflows();

        byte[] bytes = new byte[myStream.Length];
        myStream.Read(bytes, 0, (int)myStream.Length);

        // change here to your actual field name
        w.FileData = bytes;

        // change here according to your context
        context.Workflows.Add(w);
        context.SubmitChanges();
    }
}
于 2013-08-15T02:39:03.770 回答