简体   繁体   English

如何将'byte []'类型转换为'System.Data.Linq.Binary'

[英]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) )). 我的数据库中有一个WorkflowInstances表,其中包含以下字段:ID(int),Name(nvarchar(50),WorkflowID(int), Document(varbinary(MAX) ))。 I want to insert a new WorkflowInstance so I wrote this code 我想插入一个新的WorkflowInstance,所以我写了这段代码

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' 我在第15行遇到错误,错误是:无法将类型'byte []'隐式转换为'System.Data.Linq.Binary'

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将内存流转换为System.Data.Linq.Binary? - How to convert Memory Stream to System.Data.Linq.Binary? 无法将'System.Data.Linq.Binary'类型的对象强制转换为'System.Byte []' - Unable to cast object of type 'System.Data.Linq.Binary' to type 'System.Byte[]' LINQ,聚合操作不支持“System.Data.Linq.Binary”类型 - The type 'System.Data.Linq.Binary' is not supported in aggregation operations - LINQ 无法在LINQ中将类型'string'隐式转换为'System.Data.Linq.Binary - Cannot implicitly convert type 'string' to 'System.Data.Linq.Binary in LINQ to SQL 类型“ System.Data.Linq.Binary”在未引用的程序集中定义 - Type 'System.Data.Linq.Binary' is defined in an assembly that is not referenced 在C#中,我如何从URL获取图像并转换为System.Data.Linq.Binary - in C#, how can i take an image from a URL and convert to System.Data.Linq.Binary 如何在C#中将System.Data.Linq.Binary分配为null? - How to assign System.Data.Linq.Binary to null in C#? 无法从“ System.DateTime”转换为“ System.Data.Linq.Binary”错误 - Cannot convert from 'System.DateTime' to 'System.Data.Linq.Binary' error 将System.Drawing.Image转换为System.Data.Linq.Binary - Converting System.Drawing.Image to System.Data.Linq.Binary .NET Core中的等效System.Data.Linq.Binary - Equivalent System.Data.Linq.Binary in .net core
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM