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.
- inside
using
block, make use of objects ofsqlconnection
,sqlcommand
classes put in connection string , sp details respectively. you can use
sqlcommand
object fire sp usingexecutereader
, store results insqldatareader
object :sqldatareader dr1 = command.executereader();
you can read result datareader object :
int st = convert.toint32(dr1["returnres"]);
this
int
can usedecimal
, convert needed. have branch code per result obtained in variable.
hope clears idea of how proceed issue.
Comments
Post a Comment