(首先......对不起我的英文:D) 我已经在这里发布了我的问题c# Search using ComboBox and Textbox ..没有人解决我的问题,但我使用他们的代码来简化我的代码。
当我启动程序时,DataGridView
看起来很正常..我在ComboBox
中选择一个字段并输入TextBox
..结果显示但问题是......他们的另一栏已添加到DataGridView
并且它已空......我希望您帮我删除该列
Here's the image(我在stackoverflow中是新手。我没有足够的声誉来发布图片)
public void searchData()
{
string sql = "Select ID,Quantity,Unit,ItemCode,ItemName,Cbm,TotalCbm from Inventory Order By ID asc;";
cmd = new OleDbCommand(sql, con);
try
{
con.Open();
string value = cboFields.Text;
cmd.CommandText = String.Format(
@"Select ID,
Quantity,Unit,ItemCode,ItemName,Cbm,TotalCbm
from Inventory
where {0} like @searchKey Order By ID asc;", value);
cmd.Parameters.AddWithValue("@searchKey", txtSearch.Text.ToString() + "%");
OleDbDataAdapter adp= new OleDbDataAdapter(cmd);
//DataSet ds = new DataSet();
//adp.Fill(ds);
//DGVinventory.DataSource = ds;
DataTable dt = new DataTable();
adp.Fill(dt);
DGVinventory.DataSource = dt;
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
con.Close();
}
}
private void txtSearch_TextChanged(object sender, EventArgs e)
{
searchData();
}