梦幻之旅

DEBUG - 天道酬勤

   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  671 随笔 :: 6 文章 :: 256 评论 :: 0 Trackbacks
private void FillListView()
        {
            string id; 
//id号
            string loginName ; 
// 用户名
            string password ; 
// 密码
            string status; 
// 状态
            string name; 
// 姓名
            string gender; 
// 性别
            string phone; 
// 电话
            string email; 
// 电子邮件
            string address;
            string grade; 
// 年级
            string sClass; 
// 班级
            string createTime; 
//  创建时间
            string updateTime; 
//修改时间
            string remark; 
// 备注

            try
            {
                
// 构建sql
                string sql 
= "SELECT ID,login_name,PASSWORD,status,name,gender,phone,email,address,grade,class,is_using,to_char(create_time,'yyyy-mm-dd hh24:mi') createTime,to_char(update_time,'yyyy-mm-dd hh24:mi') updateTime,remark FROM t_vs_student ";
                
if (this.txtSearchName.Text.Trim() != "")
                {
                    sql 
+= string.Format(" where name like '%{0}%'", this.txtSearchName.Text.Trim());
                }

                OracleCommand command 
= new OracleCommand(sql, DBHelper.connection);
                DBHelper.connection.
Open();
                OracleDataReader dataReader 
= command.ExecuteReader();

                
// 清除列表项
                this.lvStudent.Items.Clear();
                
// 检查dataReader没有数据
                
if (!dataReader.HasRows)
                {
                    MessageBox.Show("没有找到您要找的用户", "结果提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                
else
                {
                    
while (dataReader.Read())
                    {
                        id 
= dataReader["id"].ToString();
                        loginName 
= dataReader["login_name"].ToString();
                        password 
= dataReader["password"].ToString();
                        status 
= dataReader["status"].ToString();
                        name 
= dataReader["name"].ToString();
                        gender 
= dataReader["gender"].ToString();
                        phone 
= dataReader["phone"].ToString();
                        email 
= dataReader["email"].ToString();
                        address 
= dataReader["address"].ToString();
                        grade 
= dataReader["grade"].ToString();
                        sClass 
= dataReader["class"].ToString();
                        createTime 
= dataReader["createTime"].ToString();
                        updateTime 
= dataReader["updateTime"].ToString();
                        remark 
= dataReader["remark"].ToString();
                        
                        
//loginName = (string)dataReader.Read("login_name");

                        
// 创建列表选项
                        ListViewItem lviStudent 
= new ListViewItem(loginName);

                        
// 这个值不要用户看,但是对程序员有用
                        
//lviStudent.Tag = id;

                        
// 添加一行
                        this.lvStudent.Items.
Add(lviStudent);

                        
// 添加行数据
                        lviStudent.SubItems.AddRange(new string
[] {name, gender, phone, email, address, grade, sClass,createTime,updateTime,remark});
                    }
                    dataReader.
Close();
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally 
            {
                DBHelper.connection.
Close();
            }
        
        }
posted on 2011-07-15 15:54 HUIKK 阅读(225) 评论(0)  编辑  收藏 所属分类: C#

只有注册用户登录后才能发表评论。


网站导航: