Click here to Skip to main content
15,902,634 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#

i want to connect SMS to SQL table and take specific data ,Kindly do help..Mentioned below coding ,that where have to mentioned SQL query for taking data from Table.

What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;



namespace WebApplication31
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        string MyUsername = "11111111111"; //Your Username At Sendpk.com 
        string MyPassword = "111"; //Your Password At Sendpk.com 
        string toNumber = "111111111"; //Recepient cell phone number with country code 
        string Masking = "SMS Alert"; //Your Company Brand Name 
        string MessageText = "SMS Sent using .Net";
        string jsonResponse = SendSMS ("Masking", "toNumber", "MessageText"," MyUsername", "MyPassword");

        private static string SendSMS(string p1, string p2, string p3, string p4, string p5)
        {
            throw new NotImplementedException();
        }
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            String URI = "http://Sendpk.com" +
            "/api/sms.php?" +
            "username=" + MyUsername +
            "&password=" + MyPassword +
            "&sender=" + Masking +
            "&mobile=" + toNumber +
            "&message=" + Uri.UnescapeDataString(MessageText); // Visual Studio 10-15 
            //"&message=" + System.Net.WebUtility.UrlEncode(MessageText);// Visual Studio 12 
            try
            {
                WebRequest req = WebRequest.Create(URI);
                WebResponse resp = req.GetResponse();
                var sr = new System.IO.StreamReader(resp.GetResponseStream());
                //return sr.ReadToEnd().Trim(); 
            }
            catch (WebException ex)
            {
                var httpWebResponse = ex.Response as HttpWebResponse;
                if (httpWebResponse != null)
                {
                    switch (httpWebResponse.StatusCode)
                    {
                        case HttpStatusCode.NotFound:
                        //return "404:URL not found :" + URI; 
                        //break; 
                        case HttpStatusCode.BadRequest:
                        //return "400:Bad Request"; 
                        //break; 
                        default:
                            break;
                       //return httpWebResponse.StatusCode.ToString(); 

                    }
                }
                //return null; 
            }
        }
    }
}
Posted
Updated 10-May-18 18:33pm

1 solution

You need an SMS gateway that offers an API and you need to call it. You seem to have found one, but as you don't tell us what goes wrong with this code, it's impossible to offer more specific help.

Or is your problem getting the data from SQL Server? The easiest way to do that, is to use entity framework to create a DAL to your DB, and use it to pull data from the DB. Again, very vague question, asking about some entry level stuff. You should try to do this and ask specific questions when you get stuck
 
Share this answer
 
Comments
akhter86 11-May-18 1:23am    
Thanks for your kind suggestion , i am beginner,so that why asking these kind of question ,i want just little help that how to connect this coding to SQL,and this coding is working which i share is working fine.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900