c# - Automatically Search in DataGridView -
i want have automatic search in textbox
.
this code running when i'm searching string when search integer error:
cannot perform 'like' operation on system.int32 , system.string
i hope can because need now.
private void textbox1_textchanged(object sender, eventargs e) { dataview dv = new dataview(datatable); dv.rowfilter = string.format("orderno '%{0}%'",textbox1.text); datagridview1.datasource = dv; }
you can't use like
operator compare numbers. assume want find matching order id:
dv.rowfilter = string.format("orderno = {0}", textbox1.text);
you may want use int.tryparse()
test value in textbox
first.
private void textbox1_textchanged(object sender, eventargs e) { int orderid; if (!int.tryparse(textbox1.text, out orderid)) return; // not valid number dataview dv = new dataview(datatable); dv.rowfilter = string.format("orderno = {0}", orderid); datagridview1.datasource = dv; }
if want compare order id string, must convert first:
dv.rowfilter = string.format("convert(column3, system.string) '%{0}%'", textbox1.text);
Comments
Post a Comment