c# - Get the value of a column from sql server -


i want column value database. column datatype decimal. if column value less 1, send email recipient .

the code looks :

protected void button1_click(object sender, eventargs e) {    using(sqlconnection conn = new sqlconnection())    {          // want put code in here      }     if (column less 1)     {         try         {             mailmessage mailmessage = new mailmessage();            mailmessage.to.add("me@myemail.com");            mailmessage.from = new mailaddress("fromemail@email.com");            mailmessage.subject = "asp.net e-mail test";            mailmessage.body = "hello world,\n\nthis asp.net test e-mail!";            smtpclient smtpclient = new smtpclient();             smtpclient.send(mailmessage);             response.write("e-mail sent!");            label1.text = "sent perfectly!";      }      catch (exception ex)      {       response.write("could not send e-mail - error: " + ex.message);       label1.text = "could not send e-mail - error: " + ex.message;     }   } } 

putting actual code not best solution here can follow these steps resolve this.

  1. inside using block, make use of objects of sqlconnection , sqlcommand classes put in connection string , sp details respectively.
  2. you can use sqlcommand object fire sp using executereader , store results in sqldatareader object :

    sqldatareader dr1 = command.executereader();

  3. you can read result datareader object :

    int st = convert.toint32(dr1["returnres"]);

  4. this int can use decimal , convert needed. have branch code per result obtained in variable.

hope clears idea of how proceed issue.


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -