private static void 使用原始sql命令打印字段值() { sqlconnection conn = new sqlconnection(@"data source=.sqlexpress;initial catalog=图库;integrated security=true"); try { conn.open(); console.writeline("sucess"); } catch (exception) { console.writeline("打开失败"); } sqlcommand comm = conn.createcommand(); comm.commandtext = "select * from 会员数据"; sqldatareader reader = comm.executereader(); while (reader.read()) { console.writeline("你要打印的数据:{0}", reader.getsqlint16(reader.getordinal("年龄"))); } }
改成int32程序就正确运行了
console.writeline("你要打印的数据:{0}", reader.getsqlint32(reader.getordinal("年龄")));