JScript.Net 之 SqlDataReader读取数据

类别:Asp 点击:0 评论:0 推荐:
<%@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();
}
%>

本文地址:http://com.8s8s.com/it/it7329.htm