Asp.net C # method for getting the int field value of a database

Source: Internet
Author: User
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 ")));

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.