简体   繁体   中英

How to convert type 'byte[]' to 'System.Data.Linq.Binary'

I have a WorkflowInstances table in my DB which contains this fields: ID (int), Name (nvarchar(50), WorkflowID (int), Document (varbinary(MAX) )). I want to insert a new WorkflowInstance so I wrote this code

Stream myStream = openFileDialogDoc.OpenFile();
            if (myStream != null)
            {
                using (myStream)
                {
                    WorkflowInstance w = new WorkflowInstance();

                    byte[] bytes = new byte[myStream.Length];
                    myStream.Read(bytes, 0, (int)myStream.Length);
                    w.ID = repository.WorkflowsRepository.GetMaxIDWokflowInstance() + 1;
                    w.Name = textBoxWorkflowInstanceName.Text;
                    w.CurrentStateID = repository.WorkflowsRepository.GetWorkflowFirstState((int)listBoxMyWorkflows.SelectedValue);
                    w.WorkflowID = (int)listBoxMyWorkflows.SelectedValue;
                    w.CreationDate = System.DateTime.Now.ToString();
                    w.Document = bytes;
                    RapidWorkflowDataContext context = new RapidWorkflowDataContext();
                    context.WorkflowInstances.InsertOnSubmit(w);
                    context.SubmitChanges();
                }
            }

I got an error in line 15, the error is: Cannot implicitly convert type 'byte[]' to 'System.Data.Linq.Binary'

System.Data.Linq.Binary有一个带有1个byte[]参数的构造函数:

w.Document = new System.Data.Linq.Binary(bytes);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM