Web Service = WebMethod's and Database

I am trying to write a web method that will enabled me to INSERT text directly to the sql table via a web service. I managed to view any text entered manually to the table, on the web service xml page. Want I want to do now is to be able to insert data from the web service to the database.

The Idea behind this is, for users to be able to access view and add information/text to the database via the web service. I will appreciate any help of directions towards solving the issue I’ve highlighted in red below.

The web method highlighted in red is where the problem is. I would like help on how to create/add a textbox that will insert data directly to the table. Or any other way of inserting information into the table via the web service.


namespace SkiFriendService
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["SkiFriendService.Properties.Settings.Setting"].ToString());


        [WebMethod]
        public string simpleMethod(String srt)
        {
            return "Hello "+srt;
        }


        [WebMethod]
        public int anotherSimpleMethod(int firstNum, int secondNum)
        {
            return firstNum + secondNum;
        }


        [WebMethod]
        public string[] getMessage(string from, string to) 
        {
            List<string> messages = new List<string>();
            con.Open();
                string sqlquery = string.Format("select Message from MessageTable where Sender='{0}' and Receiver='{1}'", from, to);
            SqlCommand com = new SqlCommand(sqlquery, con);
            SqlDataReader sqlReader = com.ExecuteReader();
            while (sqlReader.Read()) 
            {
                messages.Add(sqlReader.GetString(0));
            }
            con.Close();
            return messages.ToArray();
        }


      [COLOR=#ff0000]**  [WebMethod]
        public void InsertInfo(string sender, string receiver, string message)
        {
            List<string> messages = new List<string>();
            con.Open();
            string sql = "INSERT INTO MessageTable (Sender, Receiver, Message) VALUES (@Sender, @Receiver, @Message)";
            SqlCommand com = new SqlCommand(sql, con);
            SqlDataReader sqlReader = com.ExecuteReader();
            while (sqlReader.Read())
            {
                messages.Add(sqlReader.GetString(0));
            }
            con.Close();**
            
        }[/COLOR]


           


        }
       


        }



I hope I’ve been clear enough with this. I am still learning this so a lot of this is new to me. I would appreciate any help. Thank You :slight_smile: