[Asp.Net]实现提取数据到table中 不用服务器控件

来源:互联网 发布:国内工程预算软件 编辑:程序博客网 时间:2024/05/17 14:21

1.后台方法  
    public string id;
    public string usercode;
    public void tbalelist(string strsql)
    {
        string str = string.Empty;
        DBCon OAcon = new DBCon();
        SqlConnection myConn = new SqlConnection(OAcon.getOAcon());
        myConn.Open();
        SqlCommand sc = new SqlCommand(strsql, myConn);
        SqlDataReader sr = sc.ExecuteReader();
        if(sr.Read())
        {
            id=sr[0].ToString();
            usercode = sr[1].ToString();  
        }
        sr.Close();
        myConn.Close();
       
    }
2.前台
         <table align="center" border="0" cellpadding="5" cellspacing="1" width="100%">
                 <tr>
                     <td class="hback" width="5%">
                                    <font color="#cc3300"><b>ID</b></font></td>
                      <td class="hback" width="10%">
                                    <font color="#cc3300"><b>张号</b></font></td>
 
                </tr>
                 <tr>
                     <td class="hback" width="5%"><%= id %></td>
                      <td class="hback" width="10%"><%= usercode %></td>
                </tr>
          </table>

原创粉丝点击