当前位置:编程学习 > C#/ASP.NET >>

怎么用GridView 显示查询结果

怎么用GridView 显示查询结果   GridView 用绑定数据源吗 --------------------编程问答-------------------- 怎么不用datagridview呢?
  连接数据库
  读取数据库,如果你仅仅是显示数据的话,可以这样:
SqlDataReader sqldr = sqlcmd.ExecuteReader();
while (sqldr.Read())
            { 
                BindingSource BindSource = new BindingSource();
                BindSource.DataSource = sqldr;
                this.datagridview.DataSource = BindSource;
            }
 sqldr.Close();
--------------------编程问答-------------------- “System.Dat “System.Data.DataTable”不包含“MyRows”的定义,并且找不到可接受类型为“System.Data.DataTable”的第一个参数的扩展方法“MyRows”(是否缺少 using 指令或程序集引用?)

--------------------编程问答-------------------- MyRows 这个是你自己写的属性吧,需要发下你调用这个属性的代码 --------------------编程问答-------------------- 你获得数据源是一张datatable的话,直接gridview.DataSource = datatable;就可以了。不介意的话,把你的该部分代码贴出来。 --------------------编程问答-------------------- http://pan.baidu.com/share/link?shareid=134842&uk=3791987398
C#编程1200例,里面有专门讲解GirdView的章节 --------------------编程问答-------------------- error CS1061: “string”不包含“Text”的定义,并且找不到可接受类型为“string”的第一个参数的扩展方法“Text”(是否缺少 using 指令或程序集引用?)

   DataRow MyRow = ds.Tables[0].Rows[0];
        MyRow["StudentName"] = txtStudentName.Text;
        MyRow["Sex"] = txtSex.DataValueField;
        MyRow["Minzu"] = txtMinzu.Text;
        MyRow["DataOfBirth"] = txtDataOfBirth.Text;
        MyRow["Specialty"] = txtSpecialty.Text;
        MyRow["ComeFrom"] = txtComeFrom.Text;
        MyRow["BeiZhu"] = txtBeiZhu.Text; --------------------编程问答--------------------   txtStudentName.Text = MyRow["StudentName"].ToString();
            txtSex.DataValueField.Text = MyRow["Sex"].ToString();
            txtMinzu.Text = MyRow["Minzu"].ToString();
            txtDataOfBirth.Text = MyRow["DateOfBirth"].ToString();
            txtSpecialty.Text = MyRow["Specialty"].ToString();
            txtComeFrom.Text = MyRow["ComeFrom"].ToString();
            txtBeiZhu.Text = MyRow["BeiZhu"].ToString(); --------------------编程问答-------------------- DataRow MyRow = ds.Tables[0].Rows[0];
MyRow["StudentName"] = txtStudentName.Text;
ds.Tables[0].Rows[0].Rows.Add(MyRow );//添加到dataset里面
然后
this.datagridview.DataSource = ds.Tables[0];
this.datagridview.DataBind();
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,