convert system.data.linq.binary to byte[]

前端 未结 4 828
执念已碎
执念已碎 2020-12-20 11:57

I am storing bytes in a database table. When I retrieve it with Linq 2 sql I get the return type in system.data.linq.Binary.

I am not able to convert th

4条回答
  •  我在风中等你
    2020-12-20 12:37

    Probably its too late by now but may help others :)

    //testTable PK:ID, binaryData :binary(32)
    
    public void insertDummyData()
    {
        DBML.testTable v = new DBML.testTable ();
        v.ID = 1;
    
        System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
        v.binaryData = new System.Data.Linq.Binary(encoding.GetBytes("11111111000000001111111100000000"));                                                                    
    
        db.testTable.InsertOnSubmit(v);
        db.SubmitChanges();
    }
    

    Or else, Click on the Binary field from .dbml file, open properties and then change the field type from Binary to byte[] as found here

提交回复
热议问题