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.Protoc ols.SoapEx ception: Server was unable to read request. ---> System.InvalidOperationExc eption: There is an error in XML document (1, 424). ---> System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumb er(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(S tring s, NumberStyles style, NumberFormatInfo info)
at System.Xml.XmlConvert.ToIn t32(String s)
at Microsoft.Xml.Serializatio n.Generate dAssembly. XmlSeriali zationRead er1.Read2_ Employee(B oolean checkType)
at Microsoft.Xml.Serializatio n.Generate dAssembly. XmlSeriali zationRead er1.Read3_ AddNewEmpl oyee()
at Microsoft.Xml.Serializatio n.Generate dAssembly. ArrayOfObj ectSeriali zer.Deseri alize(XmlS erializati onReader reader)
at System.Xml.Serialization.X mlSerializ er.Deseria lize(XmlRe ader xmlReader, String encodingStyle, XmlDeserializationEvents events)
--- End of inner exception stack trace ---
at System.Xml.Serialization.X mlSerializ er.Deseria lize(XmlRe ader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.X mlSerializ er.Deseria lize(XmlRe ader xmlReader, String encodingStyle)
at System.Web.Services.Protoc ols.SoapSe rverProtoc ol.ReadPar ameters()
--- End of inner exception stack trace ---
at System.Web.Services.Protoc ols.SoapSe rverProtoc ol.ReadPar ameters()
at System.Web.Services.Protoc ols.WebSer viceHandle r.CoreProc essRequest ()
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.WebSer vice
{
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;Use r ID=user;Password=******"))
{
SqlCommand cmd = new SqlCommand("INSERT INTO Employees " +
"(EmployeeNumber, Title, FirstName, LastName, Salary) " +
"VALUES(@EmployeeNumber, @Title, @FirstName, @LastName, @Salary)", conn);
cmd.Parameters.AddWithValu e("@Employ eeNumber", employee.EmployeeNumber);
cmd.Parameters.AddWithValu e("@Title" , employee.Title);
cmd.Parameters.AddWithValu e("@FirstN ame", employee.FirstName);
cmd.Parameters.AddWithValu e("@LastNa me", employee.LastName);
cmd.Parameters.AddWithValu e("@Salary ", employee.Salary);
conn.Open();
rowsAffected = cmd.ExecuteNonQuery();
}
return rowsAffected;
}
}
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.Protoc
at System.Number.StringToNumb
at System.Number.ParseInt32(S
at System.Xml.XmlConvert.ToIn
at Microsoft.Xml.Serializatio
at Microsoft.Xml.Serializatio
at Microsoft.Xml.Serializatio
at System.Xml.Serialization.X
--- End of inner exception stack trace ---
at System.Xml.Serialization.X
at System.Xml.Serialization.X
at System.Web.Services.Protoc
--- End of inner exception stack trace ---
at System.Web.Services.Protoc
at System.Web.Services.Protoc
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.WebSer
{
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;Use
{
SqlCommand cmd = new SqlCommand("INSERT INTO Employees " +
"(EmployeeNumber, Title, FirstName, LastName, Salary) " +
"VALUES(@EmployeeNumber, @Title, @FirstName, @LastName, @Salary)", conn);
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
conn.Open();
rowsAffected = cmd.ExecuteNonQuery();
}
return rowsAffected;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.