我的一个sql语句 查出4个值select student.st_name,student.st_sex,studentpic.sp_picdata,lessoncard.lc_enddate from student,studentpic,lessoncard where (lessoncard.LC_card_id='" + id + "' and lessoncard.studentid=student.id and student.st_no=studentpic.sp_studentno但是我只想用前面2个,然后把前面2个传给datagridview,这样该怎么写?

解决方案 »

  1.   

    把第三列和第四列的visible设为false
      

  2.   


                dataGridView1.DataSource = dt;
                dataGridView1.Columns[2].Visible = false;
                dataGridView1.Columns[3].Visible = false;
      

  3.   

    我换个问法吧,就是如何给DataGridView添加数据,比如我想在姓名,性别后面 加一列时间(以当前时间,不是数据库查出来的)。。这样怎么添加?
      

  4.   

    只能在datatable加然后重新绑定
      

  5.   

    dataGridView1.Columns.Add(time);
    你想这列数据一值保持为当前时间?
    你的用个Timer一直给这一列赋值?
      

  6.   

    不是,我要做的东西是这样的。。我想根据输入的卡号,查询出一组数据,然后保留在dataGridView里,然后在输入另外个卡号 再查询出来另外组数据,然后继续添加在dataGridView,但是dataGridView后面的日期时间是执行这个函数时的当地时间,备注是我根据 数据表查出的ENDdate,来判断卡是否过期,备注就写 ”卡过期“,或者“卡未过期”。但是好像用dataGridView不好实现这个功能!后来,经同事提醒,我就想用Listview来实现。。好像简单点
      

  7.   

    你把那两个字段算好了 赋值给dadataGridView也可以啊//像这样
    DateTime date = Convert.ToDateTime("2011.10.01");
    dadataGridView1.Rows[0].Cells["日期时间"].Value =date ;
    dadataGridView1.Rows[0].Cells["备注"].Value = ENDdate>date ? "卡过期" : "卡未过期";
      

  8.   

    select columname as '中文名',sql语句这么写就行了
    然后再添加到datagridview中
      

  9.   

    谢谢了,虽然我已经用LISTVIEW完成这个功能了,datagridview我用的不多,非常陌生。。