• ListView


    <body>
        <form id="form1" runat="server">
        <div>
            <table>
                <thead>
                    <tr>
                        <th>
                            工号
                        </th>
                        <th>
                            姓名
                        </th>
                        <th>
                            性别
                        </th>
                        <th>
                            部门
                        </th>
                        <th>
                            角色
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <asp:ListView ID="LV" runat="server" ItemPlaceholderID="itemPlaceHolder"> 
                        <ItemTemplate>
                            <tr>
                                <td>
                                    <%# Eval("id") %>
                                </td>
                                <td>
                                    <%# Eval("name") %>
                                </td>
                                <td>
                                    <%# Eval("sex") %>
                                </td>
                                <td>
                                    <%# Eval("dep") %>
                                </td>
                                <td>
                                    <%# Eval("character")%>
                                </td>
                            </tr>
                        </ItemTemplate>
                    </asp:ListView>
                </tbody>
            </table>
        </div>
        </form>
    </body>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                BindData();
            }
        }
    
        private void BindData(){
            string sql = "select * from employee";
            LV.DataSource = new OraSqlHelper().GetEmployees(sql);
            LV.DataBind();
        }
    public List<Employee> GetEmployees(string sql)
        {
            List<Employee> employees = new List<Employee>();
            OracleDataReader result = null;
    
            OracleConnection conn = new OracleConnection(conStr);
            conn.Open();
            OracleCommand cmd = new OracleCommand(sql, conn);
            //从数据库中读取数据流存入result中
            result = cmd.ExecuteReader();
    
            while (result.Read())
            {
                Employee employee = new Employee();
    
                //result.GetOrdinal("id")是得到ID所在列的index, 
                //result.GetInt32(int n)这是将第n列的数据以Int32的格式返回 
                //result.GetString(int n)这是将第n列的数据以string 格式返回
                //result.GetDateTime(int n)这是将第n列的数据以string 格式返回
    
                //判断数据是否为空
                //objId != DBNull.Value判断对象是否为空
                //!Convert.IsDBNull(objScsj)判断DateTime是否为空
                //对象.IsNull("字段")
                //对象.ToString() == ""
                var objId = result.GetValue(result.GetOrdinal("id"));
                if (objId != DBNull.Value)
                {
                    employee.id = Convert.ToInt32(objId);
                }
                var objName = result.GetValue(result.GetOrdinal("name"));
                if (objName != DBNull.Value)
                {
                    employee.name = objName.ToString();
                }
                var objWjjid = result.GetValue(result.GetOrdinal("sex"));
                if (objWjjid != DBNull.Value)
                {
                    employee.sex = objWjjid.ToString();
                }
                var objDep = result.GetValue(result.GetOrdinal("dep"));
                if (objDep != DBNull.Value)
                {
                    employee.dep = objDep.ToString();
                }
                var objCharacter = result.GetValue(result.GetOrdinal("character"));
                if (objCharacter != DBNull.Value)
                {
                    employee.character = objCharacter.ToString();
                }
    
                //格式化输出数据
                //Console.Write("ID:{0},Name:{1},PWD:{2},Age:{3},Sex:{4},Phone{5},Address:{6}
    ", id, name, pwd, age, sex, phone, address);
                employees.Add(employee);
            }
    
            conn.Close();
            conn.Dispose();
            return employees;
        }
  • 相关阅读:
    FZU 2150 Fire Game (高姿势bfs--两个起点)(路径不重叠:一个队列同时跑)
    HDU1010 Tempter of the Bone【小狗是否能逃生----DFS奇偶剪枝(t时刻恰好到达)】
    MySQL--9存储引擎
    MySQL--7MySQL自定义函数
    MySQL--5子查询与连接小结
    MySQL--4操作数据表中的记录小结
    MySQL--6运算符和函数小结
    MySQL--8MySQL存储过程小结
    Hybrid设计--如何落地一个Hybrid项目
    Hybrid设计--离线更新
  • 原文地址:https://www.cnblogs.com/huangj/p/7698371.html
Copyright © 2020-2023  润新知