首页 > 编程 > .NET > 正文

JScript.Net 之 SqlDataReader读取数据

2024-07-10 13:03:08
字体:
来源:转载
供稿:网友
<%@import namespace="system.data.sqlclient"%>

var db : string = "server=10.1.0.1;uid=sa;pwd=123;database=db";
var sql : string = " select * from table ";

var rs = sqldatareader;
var conn : sqlconnection = new sqlconnection(db);
var cmd : sqlcommand = new sqlcommand(sql,conn);
            
try{

    conn.open();
    rs = cmd.executereader();
    
    if (rs.hasrows){
        //founded.
    }else{
        //not found.

        while(rs.read()){
            response.write(rs["id"] .tostring());
        }
    }
            
    rs.close();
    conn.close();
    
}catch(e){
    response.write("error!");
}finally{
    cmd.dispose();
    conn.dispose();
}
%>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表