winforms - Stopping Button Click Function in C# Winfoms -


i have save button grabs information , stores in sql winform. issue i'm having if click save button, still stores blank information in database. don't want this. here's code. keep in mind, actual saving, updating, getting data work perfectly.

        private void btnsave_click(object sender, eventargs e)     {         if (txtlocalsourcepath.text != null)         {             if (resourcekey == 0)             {                 connstring = configurationmanager.connectionstrings["dev"].connectionstring;                 getdata(connstring);                 insertdata(connstring);                 getdata(connstring);                 lblinsertnewrecord.visible = true;                 lblinsertnewrecord.text = string.format("you have inserted new record @ {0}", system.datetime.now);             }             else             {                 updatedata();                 getdata(connstring);                 lblinsertnewrecord.visible = true;                 lblinsertnewrecord.text = string.format("updated record @ {0}", system.datetime.now );             }             cleardata();         }         else         {             lblinsertnewrecord.visible = true;             lblinsertnewrecord.text = "cannot add record.  please select file.";         }     } 

i have tried these options: stopping function executed on winform button click how cancel event in winforms? how cancel winform button click event?

you want try if (txtlocalsourcepath.text != null && txtlocalsourcepath.text.length > 0), or solution proposed basher:

if (!string.isnullorempty(txtlocalsourcepath.text))

the .text property not null, instead blank ("") string.

edit: russ wilson's recommendation in comments handy: if (!string.isnullorwhitespace(txtlocalsourcepath.text)), guarantees string not spaces/tabs/etc.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -