Lawrence
Lawrence

Reputation: 505

Insert a variable into SQL database

Am a newbie to webservices and SQL. i have developed a webservice that inserts into a SQL database. below is my code.

 public class balanceEnquiry : System.Web.Services.WebService
 {
    [WebMethod(MessageName = "CheckBalance")]//To Check Balance......
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute(Action = "CheckBalance", RequestNamespace = "http://www.zain.com/", ResponseNamespace = "http://www.zain.com/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    public string CheckBalance(string AccountNumber, string msisdn, string pin)
    {
        ValidationAPIClient client = new ValidationAPIClient();

        //validate sub by pin
        //fetch MAI by msisdn
        //validate pin

I want to insert the msisdn entered by the user into my database. and also the response from a partner API to my webservice is as below

 return validateAccountResultItem.responseExtraData;

I want to insert the 2 in my database. How will i write my insert statement. Below is what i have been doing

cmd.CommandText = string.Format("INSERT INTO MSSG(REFERENCE_ID, TIMESTAMP, DEST_MSISDN, MESSAGE, TYPE, HOSTIP) VALUES ('1234567890', SYSDATE,'91976707759','TESTMESSAGE','0',(SELECT HOSTIP FROM SMPP_TRANSMITTER WHERE STATUS = 1 AND ROWNUM = 1))");

Instead of hardcoding the DEST_MSISDN and MESSAGE columns, i want them to be the string entered by the user and validateAccountResultItem.responseExtraData respectively.

Upvotes: 1

Views: 483

Answers (1)

jazzytomato
jazzytomato

Reputation: 7214

cmd.CommandText = string.Format("INSERT INTO MSSG(REFERENCE_ID, TIMESTAMP, DEST_MSISDN, MESSAGE, TYPE, HOSTIP) VALUES ('1234567890', SYSDATE,@DEST_MSISDN,@MESSAGE,'0',(SELECT HOSTIP FROM SMPP_TRANSMITTER WHERE STATUS = 1 AND ROWNUM = 1))");

String destMsisdn, message;

//**todo** here, retrieve user input in those two variables


cmd.Parameters.AddWithValue("@DEST_MSISDN", destMsisdn);
cmd.Parameters.AddWithValue("@MESSAGE", message);

Upvotes: 1

Related Questions