本文介绍了如何将类型'byte []'转换为'System.Data.Linq.Binary'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在数据库中有一个WorkflowInstances表,该表包含以下字段:ID(int),Name(nvarchar(50),WorkflowID(int), Document(varbinary(MAX) )).我想插入一个新的WorkflowInstance,所以我写了这段代码
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();
}
}
第15行出现错误,错误是:无法将类型'byte []'隐式转换为'System.Data.Linq.Binary'
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[]
的参数:
System.Data.Linq.Binary
has a constructor taking 1 argument of byte[]
:
w.Document = new System.Data.Linq.Binary(bytes);
这篇关于如何将类型'byte []'转换为'System.Data.Linq.Binary'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!