내 프로그램에 검색 기능을 추가하고 싶습니다. mField
및 mValue
에 대한 세터와 게터의 호텔을 고를 수 있습니다데이터 그리드에 검색 결과 묶기
public DataTable Search()
{
string SQL = "Select * from Customer where " + mField + " like '%" + mValue + "%'";
DataTable dt = new DataTable();
dt = dm.GetData(SQL);
return (dt);
}
:이 기능을 가진 클래스가 있습니다.
public DataTable GetData(string SQL)
{
SqlCommand command = new SqlCommand();
SqlDataAdapter dbAdapter = new SqlDataAdapter();
DataTable DataTable = new DataTable();
command.Connection = clsConnection.GetConnection();
command.CommandText = SQL;
dbAdapter.SelectCommand = command;
dbAdapter.Fill(DataTable);
return (DataTable);
}
검색 기능은 현재 다음과 같이 구현됩니다 :이 작동하지 않습니다
private void btnfind_Click(object sender, EventArgs e)
{
//cust is the object of class customer//
if (tbCustName.Text != "")
{
cust.Field="CustName";
cust.Value = tbCustName.Text;
}
else if (tbAddress.Text != "")
{
cust.Value = tbAddress.Text;
cust.Field="Address";
}
else if (tbEmail.Text != "")
{
cust.Value = tbEmail.Text;
cust.Field="Email";
}
else if (tbCell.Text != "")
{
cust.Value = tbCell.Text;
cust.Field = "Cell";
}
DataTable dt = new DataTable();
dt = cust.Search();
dgCustomer.DataSource = dt;
RefreshGrid();
}
private void RefreshGrid()
{
DataTable dt = new DataTable();
dt = cust.GetCustomers();
dgCustomer.DataSource = dt;
}
DM
는 방법을 GetData
을 가지고 클래스 DataManagement
의 대상이다. 나는 이유를 모른다. 도와주세요.
하지만 이미 referesh grid입니까? : – Abid
나는 이전의 refereshGrid 함수를 편집합니까, 아니면 새로운 함수를 만들 수 있습니까? – Abid