添加一个DataGridVeiw, textBox
进行数据绑定
textBox1.DataBindings.Add("Text", ds, "SysParams.KeyName");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "SysParams"; //ds是Dataset SysParams是表名好了 现在的问题是 我需要根据指定条件查询记录 如果有记录
dataGridView的指针 要移到查询出来的记录(是移动 不是只显示一条)
textBox1 也显示对应数据请问要怎么处理??
进行数据绑定
textBox1.DataBindings.Add("Text", ds, "SysParams.KeyName");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "SysParams"; //ds是Dataset SysParams是表名好了 现在的问题是 我需要根据指定条件查询记录 如果有记录
dataGridView的指针 要移到查询出来的记录(是移动 不是只显示一条)
textBox1 也显示对应数据请问要怎么处理??
直接对数据源根据条件 find即可跳到该记录。
{
string name =TextBox1.Text;//设置的查询条件,如果多条件,在后面继续添加
foreach (DataGridViewRow item in dataGridView1.Rows)
{
if (item.Selected == true) //设置如果条件不符合时 取消选中行
{
item.Selected = false;
}
if (name != "")
{
if (item.Cells["name"].Value.ToString() == name)
{
dataGridView1.CurrentCell = item.Cells[0]; //设置光标(第一行的箭头)是否为选中行
textbox1.text=item.Cells[0].Value.ToString();//要显示那个字段的信息就设置那个
return;
}
}
}
}