vb.net - How do I get system.byte to MySQL Bit type? -
i have mysql database (5.6 community) column of type bit(60). field holds values such 1001, 0011, etc. trying pass string of "1010" database through vb.net adapter. if use regular query this:
insert my_table (my_bit_field) values (b'1010');
this works , inserts string shown need use data adapter can't send query directly.
when using data adapter in vb.net, getting error saying expecting byte array. tried using that:
system.text.encoding.ascii.getbytes("1010")
but converted ascii representation of bytes (49,48,49,48).
is there better way go through data adapter , there way this?
thanks.
in case, try following convert string byte array:
dim bytes() byte = { convert.tobyte("1010", 2) }
however, breaks once have more 8 bits in string. (perhaps should) break string byte-sized sections , convert each byte, such this question. since have bit(60)
column cheat little , use this:
dim inputvalue string = "000100000010000000110000010000000101000001100000011100001000" if inputvalue.length > 60 ' 64 supported ' error end if dim longvalue ulong = convert.touint64(inputvalue, 2) dim bytes() byte = bitconverter.getbytes(longvalue) if bitconverter.islittleendian array.reverse(bytes) end if
this give byte array can presumably use in data adapter code not shown.
Comments
Post a Comment