Link to home
Start Free TrialLog in
Avatar of bwierwi
bwierwi

asked on

infopath 2007 submit data via web service to sql 2008

I am trying to submit data from an infopath 2007 form to an sql 2008 database table named "employees".  I have 5 columns in the table which i want populated when the user pushes the submit button on the form.  I made a web service to help with the data transfer which infopath connects to.  the problem i have is that when i push the submit button, i get an error on the form telling me  the following.  After the infopath error message, I have included my web service code. i would appreciate some direction in what i am doing wrong.  thank you.

The query cannot be run for the following DataObject: AddNewEmployee
InfoPath cannot run the specified query.
The SOAP response indicates that an error occurred:

System.Web.Services.Protocols.SoapException: Server was unable to read request. ---> System.InvalidOperationException: There is an error in XML document (1, 424). ---> System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.Xml.XmlConvert.ToInt32(String s)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read2_Employee(Boolean checkType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read3_AddNewEmployee()
   at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer.Deserialize(XmlSerializationReader reader)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
   at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
   --- End of inner exception stack trace ---
   at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
   at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()

WEBSERVICE CODE (C#)

 using System;
 using System.Web;
 using System.Web.Services;
 using System.Data;
 using System.Data.SqlClient;

public class Service : System.Web.Services.WebService
{
    public struct Employee
    {
        public int EmployeeNumber;
        public String Title;
        public String FirstName;
        public String LastName;
        public Decimal Salary;
    }

    [WebMethod]
    public int AddNewEmployee(Employee employee)
{
  int rowsAffected = 0;
  using (SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=Online_Content;User ID=user;Password=******"))
  {
    SqlCommand cmd = new SqlCommand("INSERT INTO Employees " +
      "(EmployeeNumber, Title, FirstName, LastName, Salary) " +
      "VALUES(@EmployeeNumber, @Title, @FirstName, @LastName, @Salary)", conn);

    cmd.Parameters.AddWithValue("@EmployeeNumber", employee.EmployeeNumber);
    cmd.Parameters.AddWithValue("@Title", employee.Title);
    cmd.Parameters.AddWithValue("@FirstName", employee.FirstName);
    cmd.Parameters.AddWithValue("@LastName", employee.LastName);
    cmd.Parameters.AddWithValue("@Salary", employee.Salary);

    conn.Open();
    rowsAffected = cmd.ExecuteNonQuery();
  }

  return rowsAffected;
  }
}
ASKER CERTIFIED SOLUTION
Avatar of Clay Fox
Clay Fox
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial