Private static void print the field value () {sqlconnection conn = new sqlconnection (@ "data source =. sqlexpress; initial catalog = Gallery; integrated security = true "); try {conn. open (); console. writeline ("sucess");} catch (exception) {console. writeline ("failed to open");} sqlcommand comm = conn. createcommand (); comm. commandtext = "select * from member data"; sqldatareader reader = comm.exe cutereader (); while (reader. read () {console. writeline ("The data you want to print: {0}", reader. getsqlint16 (reader. getordinal ("age ")));}}
I want to use the above database tutorial to use a program to get all ages, and the result is always an error, saying that the specified conversion is invalid. I have studied it myself. The int field in the original database needs to use int32 during conversion, instead of int16
The int32 program runs correctly.
Console. writeline ("The data you want to print: {0}", reader. getsqlint32 (reader. getordinal ("age ")));