C#
我正在对数据库使用实体框架
这是我要在Datagridview中搜索的代码:
private void TxtName_TextChanged(object sender, EventArgs e)
{
if (chbxSearch.Checked)
{
string strpatt = "";
strpatt = "Name";
strpatt += "like'%" + txtName.Text.Replace("'", "") + "%'";
((DataTable)dgvadministration.DataSource).DefaultView.RowFilter = strpatt;
};
}
错误当在文本中输入任何内容
无法将类型为'System.Windows.Forms.BindingSource'的对象转换为类型为'System.Data.DataTable'。'
怎么样:
private void TxtName_TextChanged(object sender, EventArgs e)
{
if (chbxSearch.Checked)
{
string strpatt = "";
strpatt = "Name";
strpatt += "like'%" + txtName.Text.Replace("'", "") + "%'";
((BindingSource)dgvadministration.DataSource).Filter = strpatt;
};
}
祝你好运。>>
此代码正在运行,谢谢您