c# - Read IP Address using SQLDataReader -
working asp.net application pull ipv4 information sql database using sqldatareader. when reading ip sql data type binary , not sure best way handle this.
since there no method sqldatareader.getipaddress() seems need use sqldatareader.getbytes()? many examples online around how since getstring simple hoping there simpler way use getbyte() or method bring in ip.
while sqlreader.read() dim lastcom system.datetime = sqlreader.getdatetime(0) debug.writeline(lastcom.tostring("mm/dd/yyyy hh:mm:ss.fff")) debug.writeline(sqlreader.getstring(1)) debug.writeline(sqlreader.getboolean(2)) debug.writeline(sqlreader.getstring(3)) debug.writeline(sqlreader.getstring(4)) label_ip = sqlreader.getstring(1) label_model.text = sqlreader.getstring(4) loop
i making assumptions how ip address stored in database (and supporting ipv4 addresses), try this:
dim ipaddr(3) byte ' assuming column #1 ip address column dim bytecount = sqlreader.getbytes(1, 0, ipaddr, 0, 4) if bytecount = 4 label_ip.text = new ipaddress(ipaddr).tostring() else console.writeline("expected 4 bytes ip address") end if
Comments
Post a Comment