using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Data.SqlClient; using System.Configuration; using System.Xml.Serialization; using System.Net; using System.Data; namespace InfoPathFormWebServices { /// /// Summary description for Service1 /// [WebService(Namespace = "http://xyz/")] [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 RequestFormWebServices : System.Web.Services.WebService { [WebMethod(Description = "Adds Request Form Fields to the database.")] public void SubmitRequestForm(string RequestorLastName, string RequestorFirstName, string RequestorPhone) { string connectionString = ConfigurationManager.ConnectionStrings["RequestForms"].ConnectionString; using (SqlConnection conn = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand(); cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = "INSERT INTO RequestForms" //+ "(RequestorFirstName, RequestorLastName, RequestorPhone) " //+ "VALUES (@RequestorFirstName, @RequestorLastName, @RequestorPhone)"; cmd.Parameters.AddWithValue("RequestorFirstName", RequestorFirstName); cmd.Parameters.AddWithValue("RequestorLastName", RequestorLastName); cmd.Parameters.AddWithValue("RequestorPhone", RequestorPhone); cmd.Parameters.AddWithValue("RequestorEmail", RequestorEmail); cmd.Connection = conn; try { conn.Open(); cmd.ExecuteNonQuery(); } catch { // Handle the error using your own preferred error-handling method } finally { conn.Close(); } } }