风流邪君txt全集下载:(c#语言)datagrid的问题?谢谢

来源:百度文库 编辑:中科新闻网 时间:2024/04/25 19:49:34
(c#语言)datagrid中怎么只显示特定的行?怎么通过参数,当某些列属性的值为textBox的TEXT 属性时,在DATAGIRD显示那些元组?例如:通过药品编号为"001",在datagrid中只显示编号为"001"的行?
谢谢你!!!是winform
this.sqlSelectCommand1.CommandText = "SELECT ..," +" FROM medinfo WHERE (药品编号 = @药品编号)";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@药品编号", System.Data.SqlDbType.VarChar, 7, "药品编号"));
this.sqlSelectCommand1.Parameters["@药品编号"].Value=this.textBox4.Text;
this.sqlConnection1.ConnectionString = "..."
提示是this.sqlSelectCommand1.Parameters["@药品编号"].Value=this.textBox4.Text;错了 怎么改啊?

WebForm还是WinForm?

首先你应该清楚DataGrid裏面DataSource其实就是一个DataTable

你可以查询的时候就把条件加进去,返回的也就是经过处理的结果集了。
比如
SqlDataAdapter adp = new SqlDataAdapter("select * from tablename where type = @type", new SqlConnection(connStr));
adp.SelectCommand.Parameters.Add("@type", SqlDbType.NChar);
adp.SelectCommand.Parameters["@type"].Value = yourType;
adp.Fill(dt);

也可以用下面这种方法,可以减轻数据库的负担。

dt.DefaultView.RowFilter = "type='001'";

dt是你原先的DataTable ,RowFilter 是查询条件

这些都是数据处理的基础。必须得搞清楚地

好多都是可以通过数据库的操作实现的