c# - error on empty textbox -


i want search on grid view use code:

protected void search_click(object sender, eventargs e) {     string qu = "select * [users] (([kind] = @kind) or ([family] '%' + @family + '%') or ([name] '%' + @name + '%') or ([username] '%' + @username + '%') or ([tarikhozviyat] < @tarikhozviyat) or ([tarikhozviyat] > @tarikhozviyat2))";     sqlcommand cmd = new sqlcommand(qu, con);      cmd.parameters.addwithvalue("@name", nametxt.text);     cmd.parameters.addwithvalue("@family", familytxt.text);     cmd.parameters.addwithvalue("@kind", kind.text);      cmd.parameters.addwithvalue("@username", usernametxt.text);     cmd.parameters.addwithvalue("@tarikhozviyat", sdatetxt.text);     cmd.parameters.addwithvalue("@tarikhozviyat2", edatetxt.text);     con.open();      cmd.executenonquery();     con.close();     showdata(); } 

if fill several textboxes not of them ask me fill run search

replace line:

string qu = "select * [users] (([kind] = @kind) or ([family] '%' + @family + '%') or ([name] '%' + @name + '%') or ([username] '%' + @username + '%') or ([tarikhozviyat] < @tarikhozviyat) or ([tarikhozviyat] > @tarikhozviyat2))"; 

with

string qu = "select * [users] (@kind='' or [kind] = @kind) , (@family ='' or [family] '%' + @family + '%') , (@name = '' or [name] '%' + @name + '%') , (@username = '' or [username] '%' + @username + '%') , (@tarikhozviyat='' or [tarikhozviyat] < @tarikhozviyat) , (@tarikhozviyat2 = '' or [tarikhozviyat] > @tarikhozviyat2))"; 

it search combinations of parameters of them may empty , query suppress them.

i hope helpful you:)


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -