2013-08-20 28 views
5

Ho una tabella WorkflowInstances nel mio DB che contiene questi campi: ID (int), Name (nvarchar (50), WorkflowID (int), Documento (varbinary (MAX))). voglio inserire un nuovo WorkflowInstance così ho scritto questo codiceCome convertire il tipo 'byte []' in 'System.Data.Linq.Binary'

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(); 
       } 
      } 

ho ottenuto un errore nella riga 15, l'errore è: Impossibile convertire implicitamente il tipo 'byte []' a 'System.Data.Linq.Binary '

risposta

12

System.Data.Linq.Binary ha un costruttore di prendere 1 argomento byte[]:

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