Submitting InfoPath Browser Form Repeating Sections to Access

D

Developer

Hi,

We have implemented an InfoPath 2007 Browser Form that submits data using a
web service to an Access 2002 Database along the same lines as S.Y.M
Wong-A-Ton's article at
http://www.bizsupportonline.net/inf...om-infopath-to-mysql-database-web-service.htm.

The issue is that only data for the form's first repeating section is
submitted to the database. Data for additional sections a user adds seem to
get lost.

Any direction provided towards resolving this will be appreciated. Thank you.
 
D

Don Reamey \(MSFT\)

Without seeing what your web service is doing there is not much advice than
can be given.

I would recommend debugging your web service to see how data is getting
inserted into a the table.

--
Don Reamey
Microsoft
Software Development Engineer
InfoPath Forms Server
http://blogs.officezealot.com/dreamey
 
D

Developer

Thanks for your response Don.

My web service simply inserts data into the tables of the Access database. I
have tried 'using Microsoft.Office.InfoPath' to enable iterating repeating
sections but have always encountered a reference error even after linking to
the Microsoft.Office.InfoPath.dll file.

How do I loop through repeating sections in the web service?

The web service is as follows:

<%@ WebService Language="C#" Class="submitForm" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.OleDb;
using System.Xml;
using System.Xml.XPath;

[WebService(Namespace = "http://localhost/submitForm")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class submitForm : WebService {

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\Database\DB.mdb";

public struct Details
{
public String FirstName;
public String LastName;
public DateTime DoB;

public String SupervisorName;
public DateTime SupervisedDate;
public String SupervisorPhone;
public String SupervisorEmail;

}

[WebMethod]
public void addNewDetails(Details details)
{

OleDbConnection connection = new OleDbConnection(connectionString);
OleDbCommand command = new OleDbCommand("INSERT INTO [Table1] (FirstName,
LastName, DoB) VALUES (@FirstName, @LastName, @DoB)", connection);

command.Parameters.AddWithValue("@FirstName", details.FirstName);
command.Parameters.AddWithValue("@LastName", details.LastName);
command.Parameters.AddWithValue("@DoB", details.DoB);

command.Connection = connection;
command.Connection.Open();
command.ExecuteNonQuery();

OleDbCommand command2 = new OleDbCommand("INSERT INTO [Table2]
(SupervisorName, SupervisedDate, SupervisorPhone, SupervisorEmail) VALUES
(@SupervisorName, @SupervisedDate, @SupervisorPhone, @SupervisorEmail)",
connection);

command2.Parameters.AddWithValue("@SupervisorName", details.SupervisorName);
command2.Parameters.AddWithValue("@SupervisedDate", details.SupervisedDate);
command2.Parameters.AddWithValue("@SupervisorPhone",
details.SupervisorPhone);
command2.Parameters.AddWithValue("@SupervisorEmail",
details.SupervisorEmail);

command2.Connection = connection;
command.Connection.Close();
command2.Connection.Open();
command2.ExecuteNonQuery();
command2.Connection.Close();

}

}
 
D

Don Reamey

You need to use XPath to loop through the repeating sections / table. A
repeating section / table in InfoPath is just XML.

It will looks something like this:
<my:fields>
<my:group3>
<my:group4>
<my:field5>one</my:field5>
<my:field6></my:field6>
<my:field7></my:field7>
</my:group4>
<my:group4>
<my:field5>two</my:field5>
<my:field6></my:field6>
<my:field7></my:field7>
</my:group4>
<my:group4>
<my:field5>three</my:field5>
<my:field6></my:field6>
<my:field7></my:field7>
</my:group4>
</my:group3>
</my:fields>
You will need to use an xpath to select the repeating rows. It should look
something like /my:fields/my:group

This should return a node iterator that you can use to walk over each row
and insert each row into the database.

I would recommend you build a sample application and start using the
System.Xml namespace to learn more about manipulating XML through code.

Don Reamey
Software Development Engineer
Microsoft

Developer said:
Thanks for your response Don.

My web service simply inserts data into the tables of the Access database. I
have tried 'using Microsoft.Office.InfoPath' to enable iterating repeating
sections but have always encountered a reference error even after linking to
the Microsoft.Office.InfoPath.dll file.

How do I loop through repeating sections in the web service?

The web service is as follows:

<%@ WebService Language="C#" Class="submitForm" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.OleDb;
using System.Xml;
using System.Xml.XPath;

[WebService(Namespace = "http://localhost/submitForm")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class submitForm : WebService {

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\Database\DB.mdb";

public struct Details
{
public String FirstName;
public String LastName;
public DateTime DoB;

public String SupervisorName;
public DateTime SupervisedDate;
public String SupervisorPhone;
public String SupervisorEmail;

}

[WebMethod]
public void addNewDetails(Details details)
{

OleDbConnection connection = new OleDbConnection(connectionString);
OleDbCommand command = new OleDbCommand("INSERT INTO [Table1] (FirstName,
LastName, DoB) VALUES (@FirstName, @LastName, @DoB)", connection);

command.Parameters.AddWithValue("@FirstName", details.FirstName);
command.Parameters.AddWithValue("@LastName", details.LastName);
command.Parameters.AddWithValue("@DoB", details.DoB);

command.Connection = connection;
command.Connection.Open();
command.ExecuteNonQuery();

OleDbCommand command2 = new OleDbCommand("INSERT INTO [Table2]
(SupervisorName, SupervisedDate, SupervisorPhone, SupervisorEmail) VALUES
(@SupervisorName, @SupervisedDate, @SupervisorPhone, @SupervisorEmail)",
connection);

command2.Parameters.AddWithValue("@SupervisorName", details.SupervisorName);
command2.Parameters.AddWithValue("@SupervisedDate", details.SupervisedDate);
command2.Parameters.AddWithValue("@SupervisorPhone",
details.SupervisorPhone);
command2.Parameters.AddWithValue("@SupervisorEmail",
details.SupervisorEmail);

command2.Connection = connection;
command.Connection.Close();
command2.Connection.Open();
command2.ExecuteNonQuery();
command2.Connection.Close();

}

}

Don Reamey (MSFT) said:
Without seeing what your web service is doing there is not much advice than
can be given.

I would recommend debugging your web service to see how data is getting
inserted into a the table.

--
Don Reamey
Microsoft
Software Development Engineer
InfoPath Forms Server
http://blogs.officezealot.com/dreamey
 
D

Developer

Hi Don,

If I get you correctly, I am already using System.XML but seem to need a way
of accessing the repeating section from code.
'XPathNavigator domNav = this.MainDataSource.CreateNavigator();' does not
work as it returns the compilation error "The name 'this' does not exist in
the current context".

Is there a different reference other than - 'using System.XML.XPath' - that
I should be using?

Don Reamey said:
You need to use XPath to loop through the repeating sections / table. A
repeating section / table in InfoPath is just XML.

It will looks something like this:
<my:fields>
<my:group3>
<my:group4>
<my:field5>one</my:field5>
<my:field6></my:field6>
<my:field7></my:field7>
</my:group4>
<my:group4>
<my:field5>two</my:field5>
<my:field6></my:field6>
<my:field7></my:field7>
</my:group4>
<my:group4>
<my:field5>three</my:field5>
<my:field6></my:field6>
<my:field7></my:field7>
</my:group4>
</my:group3>
</my:fields>
You will need to use an xpath to select the repeating rows. It should look
something like /my:fields/my:group

This should return a node iterator that you can use to walk over each row
and insert each row into the database.

I would recommend you build a sample application and start using the
System.Xml namespace to learn more about manipulating XML through code.

Don Reamey
Software Development Engineer
Microsoft

Developer said:
Thanks for your response Don.

My web service simply inserts data into the tables of the Access database. I
have tried 'using Microsoft.Office.InfoPath' to enable iterating repeating
sections but have always encountered a reference error even after linking to
the Microsoft.Office.InfoPath.dll file.

How do I loop through repeating sections in the web service?

The web service is as follows:

<%@ WebService Language="C#" Class="submitForm" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.OleDb;
using System.Xml;
using System.Xml.XPath;

[WebService(Namespace = "http://localhost/submitForm")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class submitForm : WebService {

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\Database\DB.mdb";

public struct Details
{
public String FirstName;
public String LastName;
public DateTime DoB;

public String SupervisorName;
public DateTime SupervisedDate;
public String SupervisorPhone;
public String SupervisorEmail;

}

[WebMethod]
public void addNewDetails(Details details)
{

OleDbConnection connection = new OleDbConnection(connectionString);
OleDbCommand command = new OleDbCommand("INSERT INTO [Table1] (FirstName,
LastName, DoB) VALUES (@FirstName, @LastName, @DoB)", connection);

command.Parameters.AddWithValue("@FirstName", details.FirstName);
command.Parameters.AddWithValue("@LastName", details.LastName);
command.Parameters.AddWithValue("@DoB", details.DoB);

command.Connection = connection;
command.Connection.Open();
command.ExecuteNonQuery();

OleDbCommand command2 = new OleDbCommand("INSERT INTO [Table2]
(SupervisorName, SupervisedDate, SupervisorPhone, SupervisorEmail) VALUES
(@SupervisorName, @SupervisedDate, @SupervisorPhone, @SupervisorEmail)",
connection);

command2.Parameters.AddWithValue("@SupervisorName", details.SupervisorName);
command2.Parameters.AddWithValue("@SupervisedDate", details.SupervisedDate);
command2.Parameters.AddWithValue("@SupervisorPhone",
details.SupervisorPhone);
command2.Parameters.AddWithValue("@SupervisorEmail",
details.SupervisorEmail);

command2.Connection = connection;
command.Connection.Close();
command2.Connection.Open();
command2.ExecuteNonQuery();
command2.Connection.Close();

}

}

Don Reamey (MSFT) said:
Without seeing what your web service is doing there is not much advice than
can be given.

I would recommend debugging your web service to see how data is getting
inserted into a the table.

--
Don Reamey
Microsoft
Software Development Engineer
InfoPath Forms Server
http://blogs.officezealot.com/dreamey


Hi,

We have implemented an InfoPath 2007 Browser Form that submits data using
a
web service to an Access 2002 Database along the same lines as S.Y.M
Wong-A-Ton's article at
http://www.bizsupportonline.net/inf...om-infopath-to-mysql-database-web-service.htm.

The issue is that only data for the form's first repeating section is
submitted to the database. Data for additional sections a user adds seem
to
get lost.

Any direction provided towards resolving this will be appreciated. Thank
you.
 
D

Don Reamey \(MSFT\)

Looking at your code in the previous message I don't see any use of
System.Xml. Also the InfoPath object model will not be available in the web
service.

Is your submit connection set up to submit the entire XML document including
the PI?

You should make your web service that accepts an XML document as follows:

[WebMethod]
public void Submit(System.Xml.XmlDocument xmlData)
{
System.Xml.XmlNodeList nodeList =
xmlData.SelectNodes("my:Fields/my:group1");
nodeList.GetEnumerator();

//for each item
//Inserting repeating row data in the database
}

The web service is where you would need to create an XPath into the document
to get the repeating table.

Once you have the nodeList you can iterate over it and insert into the
database.

--
Don Reamey
Software Development Engineer
InfoPath Forms Server
Microsoft Corporation
http://blogs.officezealot.com/dreamey

Developer said:
Hi Don,

If I get you correctly, I am already using System.XML but seem to need a
way
of accessing the repeating section from code.
'XPathNavigator domNav = this.MainDataSource.CreateNavigator();' does not
work as it returns the compilation error "The name 'this' does not exist
in
the current context".

Is there a different reference other than - 'using System.XML.XPath' -
that
I should be using?

Don Reamey said:
You need to use XPath to loop through the repeating sections / table. A
repeating section / table in InfoPath is just XML.

It will looks something like this:
<my:fields>
<my:group3>
<my:group4>
<my:field5>one</my:field5>
<my:field6></my:field6>
<my:field7></my:field7>
</my:group4>
<my:group4>
<my:field5>two</my:field5>
<my:field6></my:field6>
<my:field7></my:field7>
</my:group4>
<my:group4>
<my:field5>three</my:field5>
<my:field6></my:field6>
<my:field7></my:field7>
</my:group4>
</my:group3>
</my:fields>
You will need to use an xpath to select the repeating rows. It should
look
something like /my:fields/my:group

This should return a node iterator that you can use to walk over each row
and insert each row into the database.

I would recommend you build a sample application and start using the
System.Xml namespace to learn more about manipulating XML through code.

Don Reamey
Software Development Engineer
Microsoft

Developer said:
Thanks for your response Don.

My web service simply inserts data into the tables of the Access
database. I
have tried 'using Microsoft.Office.InfoPath' to enable iterating
repeating
sections but have always encountered a reference error even after
linking to
the Microsoft.Office.InfoPath.dll file.

How do I loop through repeating sections in the web service?

The web service is as follows:

<%@ WebService Language="C#" Class="submitForm" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.OleDb;
using System.Xml;
using System.Xml.XPath;

[WebService(Namespace = "http://localhost/submitForm")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class submitForm : WebService {

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\Database\DB.mdb";

public struct Details
{
public String FirstName;
public String LastName;
public DateTime DoB;

public String SupervisorName;
public DateTime SupervisedDate;
public String SupervisorPhone;
public String SupervisorEmail;

}

[WebMethod]
public void addNewDetails(Details details)
{

OleDbConnection connection = new OleDbConnection(connectionString);
OleDbCommand command = new OleDbCommand("INSERT INTO [Table1]
(FirstName,
LastName, DoB) VALUES (@FirstName, @LastName, @DoB)", connection);

command.Parameters.AddWithValue("@FirstName", details.FirstName);
command.Parameters.AddWithValue("@LastName", details.LastName);
command.Parameters.AddWithValue("@DoB", details.DoB);

command.Connection = connection;
command.Connection.Open();
command.ExecuteNonQuery();

OleDbCommand command2 = new OleDbCommand("INSERT INTO [Table2]
(SupervisorName, SupervisedDate, SupervisorPhone, SupervisorEmail)
VALUES
(@SupervisorName, @SupervisedDate, @SupervisorPhone,
@SupervisorEmail)",
connection);

command2.Parameters.AddWithValue("@SupervisorName",
details.SupervisorName);
command2.Parameters.AddWithValue("@SupervisedDate",
details.SupervisedDate);
command2.Parameters.AddWithValue("@SupervisorPhone",
details.SupervisorPhone);
command2.Parameters.AddWithValue("@SupervisorEmail",
details.SupervisorEmail);

command2.Connection = connection;
command.Connection.Close();
command2.Connection.Open();
command2.ExecuteNonQuery();
command2.Connection.Close();

}

}

:

Without seeing what your web service is doing there is not much
advice than
can be given.

I would recommend debugging your web service to see how data is
getting
inserted into a the table.

--
Don Reamey
Microsoft
Software Development Engineer
InfoPath Forms Server
http://blogs.officezealot.com/dreamey


Hi,

We have implemented an InfoPath 2007 Browser Form that submits data
using
a
web service to an Access 2002 Database along the same lines as
S.Y.M
Wong-A-Ton's article at
http://www.bizsupportonline.net/inf...om-infopath-to-mysql-database-web-service.htm.

The issue is that only data for the form's first repeating section
is
submitted to the database. Data for additional sections a user adds
seem
to
get lost.

Any direction provided towards resolving this will be appreciated.
Thank
you.
 
D

Developer

I have got a Submit button with 'Rules and Custom code' Action which includes
a rule (amongst others) for a data connection to the Web service (secondary
data source) I supplied earlier. The rule in question sets the fields of the
secondary data source with values from the Main data source and then writes
these to the database using the addNewDetails WebMethod. It seems I need to
remove these 'Set a field's value' rules and use code instead?

Am I correct in thinking that I need to add another WebMethod based on the
example you gave for 'Submit' and then call the method from the event handler
of the submit button?

Thanks for your help.

Don Reamey (MSFT) said:
Looking at your code in the previous message I don't see any use of
System.Xml. Also the InfoPath object model will not be available in the web
service.

Is your submit connection set up to submit the entire XML document including
the PI?

You should make your web service that accepts an XML document as follows:

[WebMethod]
public void Submit(System.Xml.XmlDocument xmlData)
{
System.Xml.XmlNodeList nodeList =
xmlData.SelectNodes("my:Fields/my:group1");
nodeList.GetEnumerator();

//for each item
//Inserting repeating row data in the database
}

The web service is where you would need to create an XPath into the document
to get the repeating table.

Once you have the nodeList you can iterate over it and insert into the
database.

--
Don Reamey
Software Development Engineer
InfoPath Forms Server
Microsoft Corporation
http://blogs.officezealot.com/dreamey

Developer said:
Hi Don,

If I get you correctly, I am already using System.XML but seem to need a
way
of accessing the repeating section from code.
'XPathNavigator domNav = this.MainDataSource.CreateNavigator();' does not
work as it returns the compilation error "The name 'this' does not exist
in
the current context".

Is there a different reference other than - 'using System.XML.XPath' -
that
I should be using?

Don Reamey said:
You need to use XPath to loop through the repeating sections / table. A
repeating section / table in InfoPath is just XML.

It will looks something like this:
<my:fields>
<my:group3>
<my:group4>
<my:field5>one</my:field5>
<my:field6></my:field6>
<my:field7></my:field7>
</my:group4>
<my:group4>
<my:field5>two</my:field5>
<my:field6></my:field6>
<my:field7></my:field7>
</my:group4>
<my:group4>
<my:field5>three</my:field5>
<my:field6></my:field6>
<my:field7></my:field7>
</my:group4>
</my:group3>
</my:fields>
You will need to use an xpath to select the repeating rows. It should
look
something like /my:fields/my:group

This should return a node iterator that you can use to walk over each row
and insert each row into the database.

I would recommend you build a sample application and start using the
System.Xml namespace to learn more about manipulating XML through code.

Don Reamey
Software Development Engineer
Microsoft

:

Thanks for your response Don.

My web service simply inserts data into the tables of the Access
database. I
have tried 'using Microsoft.Office.InfoPath' to enable iterating
repeating
sections but have always encountered a reference error even after
linking to
the Microsoft.Office.InfoPath.dll file.

How do I loop through repeating sections in the web service?

The web service is as follows:

<%@ WebService Language="C#" Class="submitForm" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.OleDb;
using System.Xml;
using System.Xml.XPath;

[WebService(Namespace = "http://localhost/submitForm")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class submitForm : WebService {

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\Database\DB.mdb";

public struct Details
{
public String FirstName;
public String LastName;
public DateTime DoB;

public String SupervisorName;
public DateTime SupervisedDate;
public String SupervisorPhone;
public String SupervisorEmail;

}

[WebMethod]
public void addNewDetails(Details details)
{

OleDbConnection connection = new OleDbConnection(connectionString);
OleDbCommand command = new OleDbCommand("INSERT INTO [Table1]
(FirstName,
LastName, DoB) VALUES (@FirstName, @LastName, @DoB)", connection);

command.Parameters.AddWithValue("@FirstName", details.FirstName);
command.Parameters.AddWithValue("@LastName", details.LastName);
command.Parameters.AddWithValue("@DoB", details.DoB);

command.Connection = connection;
command.Connection.Open();
command.ExecuteNonQuery();

OleDbCommand command2 = new OleDbCommand("INSERT INTO [Table2]
(SupervisorName, SupervisedDate, SupervisorPhone, SupervisorEmail)
VALUES
(@SupervisorName, @SupervisedDate, @SupervisorPhone,
@SupervisorEmail)",
connection);

command2.Parameters.AddWithValue("@SupervisorName",
details.SupervisorName);
command2.Parameters.AddWithValue("@SupervisedDate",
details.SupervisedDate);
command2.Parameters.AddWithValue("@SupervisorPhone",
details.SupervisorPhone);
command2.Parameters.AddWithValue("@SupervisorEmail",
details.SupervisorEmail);

command2.Connection = connection;
command.Connection.Close();
command2.Connection.Open();
command2.ExecuteNonQuery();
command2.Connection.Close();

}

}

:

Without seeing what your web service is doing there is not much
advice than
can be given.

I would recommend debugging your web service to see how data is
getting
inserted into a the table.

--
Don Reamey
Microsoft
Software Development Engineer
InfoPath Forms Server
http://blogs.officezealot.com/dreamey


Hi,

We have implemented an InfoPath 2007 Browser Form that submits data
using
a
web service to an Access 2002 Database along the same lines as
S.Y.M
Wong-A-Ton's article at
http://www.bizsupportonline.net/inf...om-infopath-to-mysql-database-web-service.htm.

The issue is that only data for the form's first repeating section
is
submitted to the database. Data for additional sections a user adds
seem
to
get lost.

Any direction provided towards resolving this will be appreciated.
Thank
you.
 
D

Don Reamey \(MSFT\)

I can't say for sure if you need to remove your existing web method. All I'm
saying is that you need to loop through the XML for the repeating table and
manually insert each row into the table. Assuming that you want each row of
the repeating table to appear as a distict row in the database.

--
Don Reamey
Microsoft
Software Development Engineer
InfoPath Forms Server
http://blogs.officezealot.com/dreamey

Developer said:
I have got a Submit button with 'Rules and Custom code' Action which
includes
a rule (amongst others) for a data connection to the Web service
(secondary
data source) I supplied earlier. The rule in question sets the fields of
the
secondary data source with values from the Main data source and then
writes
these to the database using the addNewDetails WebMethod. It seems I need
to
remove these 'Set a field's value' rules and use code instead?

Am I correct in thinking that I need to add another WebMethod based on the
example you gave for 'Submit' and then call the method from the event
handler
of the submit button?

Thanks for your help.

Don Reamey (MSFT) said:
Looking at your code in the previous message I don't see any use of
System.Xml. Also the InfoPath object model will not be available in the
web
service.

Is your submit connection set up to submit the entire XML document
including
the PI?

You should make your web service that accepts an XML document as follows:

[WebMethod]
public void Submit(System.Xml.XmlDocument xmlData)
{
System.Xml.XmlNodeList nodeList =
xmlData.SelectNodes("my:Fields/my:group1");
nodeList.GetEnumerator();

//for each item
//Inserting repeating row data in the database
}

The web service is where you would need to create an XPath into the
document
to get the repeating table.

Once you have the nodeList you can iterate over it and insert into the
database.

--
Don Reamey
Software Development Engineer
InfoPath Forms Server
Microsoft Corporation
http://blogs.officezealot.com/dreamey

Developer said:
Hi Don,

If I get you correctly, I am already using System.XML but seem to need
a
way
of accessing the repeating section from code.
'XPathNavigator domNav = this.MainDataSource.CreateNavigator();' does
not
work as it returns the compilation error "The name 'this' does not
exist
in
the current context".

Is there a different reference other than - 'using System.XML.XPath' -
that
I should be using?

:

You need to use XPath to loop through the repeating sections / table.
A
repeating section / table in InfoPath is just XML.

It will looks something like this:
<my:fields>
<my:group3>
<my:group4>
<my:field5>one</my:field5>
<my:field6></my:field6>
<my:field7></my:field7>
</my:group4>
<my:group4>
<my:field5>two</my:field5>
<my:field6></my:field6>
<my:field7></my:field7>
</my:group4>
<my:group4>
<my:field5>three</my:field5>
<my:field6></my:field6>
<my:field7></my:field7>
</my:group4>
</my:group3>
</my:fields>
You will need to use an xpath to select the repeating rows. It should
look
something like /my:fields/my:group

This should return a node iterator that you can use to walk over each
row
and insert each row into the database.

I would recommend you build a sample application and start using the
System.Xml namespace to learn more about manipulating XML through
code.

Don Reamey
Software Development Engineer
Microsoft

:

Thanks for your response Don.

My web service simply inserts data into the tables of the Access
database. I
have tried 'using Microsoft.Office.InfoPath' to enable iterating
repeating
sections but have always encountered a reference error even after
linking to
the Microsoft.Office.InfoPath.dll file.

How do I loop through repeating sections in the web service?

The web service is as follows:

<%@ WebService Language="C#" Class="submitForm" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.OleDb;
using System.Xml;
using System.Xml.XPath;

[WebService(Namespace = "http://localhost/submitForm")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class submitForm : WebService {

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;
Data
Source=C:\Database\DB.mdb";

public struct Details
{
public String FirstName;
public String LastName;
public DateTime DoB;

public String SupervisorName;
public DateTime SupervisedDate;
public String SupervisorPhone;
public String SupervisorEmail;

}

[WebMethod]
public void addNewDetails(Details details)
{

OleDbConnection connection = new OleDbConnection(connectionString);
OleDbCommand command = new OleDbCommand("INSERT INTO [Table1]
(FirstName,
LastName, DoB) VALUES (@FirstName, @LastName, @DoB)", connection);

command.Parameters.AddWithValue("@FirstName", details.FirstName);
command.Parameters.AddWithValue("@LastName", details.LastName);
command.Parameters.AddWithValue("@DoB", details.DoB);

command.Connection = connection;
command.Connection.Open();
command.ExecuteNonQuery();

OleDbCommand command2 = new OleDbCommand("INSERT INTO [Table2]
(SupervisorName, SupervisedDate, SupervisorPhone, SupervisorEmail)
VALUES
(@SupervisorName, @SupervisedDate, @SupervisorPhone,
@SupervisorEmail)",
connection);

command2.Parameters.AddWithValue("@SupervisorName",
details.SupervisorName);
command2.Parameters.AddWithValue("@SupervisedDate",
details.SupervisedDate);
command2.Parameters.AddWithValue("@SupervisorPhone",
details.SupervisorPhone);
command2.Parameters.AddWithValue("@SupervisorEmail",
details.SupervisorEmail);

command2.Connection = connection;
command.Connection.Close();
command2.Connection.Open();
command2.ExecuteNonQuery();
command2.Connection.Close();

}

}

:

Without seeing what your web service is doing there is not much
advice than
can be given.

I would recommend debugging your web service to see how data is
getting
inserted into a the table.

--
Don Reamey
Microsoft
Software Development Engineer
InfoPath Forms Server
http://blogs.officezealot.com/dreamey


Hi,

We have implemented an InfoPath 2007 Browser Form that submits
data
using
a
web service to an Access 2002 Database along the same lines as
S.Y.M
Wong-A-Ton's article at
http://www.bizsupportonline.net/inf...om-infopath-to-mysql-database-web-service.htm.

The issue is that only data for the form's first repeating
section
is
submitted to the database. Data for additional sections a user
adds
seem
to
get lost.

Any direction provided towards resolving this will be
appreciated.
Thank
you.
 
D

Developer

Thanks for your help.

Don Reamey (MSFT) said:
I can't say for sure if you need to remove your existing web method. All I'm
saying is that you need to loop through the XML for the repeating table and
manually insert each row into the table. Assuming that you want each row of
the repeating table to appear as a distict row in the database.

--
Don Reamey
Microsoft
Software Development Engineer
InfoPath Forms Server
http://blogs.officezealot.com/dreamey

Developer said:
I have got a Submit button with 'Rules and Custom code' Action which
includes
a rule (amongst others) for a data connection to the Web service
(secondary
data source) I supplied earlier. The rule in question sets the fields of
the
secondary data source with values from the Main data source and then
writes
these to the database using the addNewDetails WebMethod. It seems I need
to
remove these 'Set a field's value' rules and use code instead?

Am I correct in thinking that I need to add another WebMethod based on the
example you gave for 'Submit' and then call the method from the event
handler
of the submit button?

Thanks for your help.

Don Reamey (MSFT) said:
Looking at your code in the previous message I don't see any use of
System.Xml. Also the InfoPath object model will not be available in the
web
service.

Is your submit connection set up to submit the entire XML document
including
the PI?

You should make your web service that accepts an XML document as follows:

[WebMethod]
public void Submit(System.Xml.XmlDocument xmlData)
{
System.Xml.XmlNodeList nodeList =
xmlData.SelectNodes("my:Fields/my:group1");
nodeList.GetEnumerator();

//for each item
//Inserting repeating row data in the database
}

The web service is where you would need to create an XPath into the
document
to get the repeating table.

Once you have the nodeList you can iterate over it and insert into the
database.

--
Don Reamey
Software Development Engineer
InfoPath Forms Server
Microsoft Corporation
http://blogs.officezealot.com/dreamey

Hi Don,

If I get you correctly, I am already using System.XML but seem to need
a
way
of accessing the repeating section from code.
'XPathNavigator domNav = this.MainDataSource.CreateNavigator();' does
not
work as it returns the compilation error "The name 'this' does not
exist
in
the current context".

Is there a different reference other than - 'using System.XML.XPath' -
that
I should be using?

:

You need to use XPath to loop through the repeating sections / table.
A
repeating section / table in InfoPath is just XML.

It will looks something like this:
<my:fields>
<my:group3>
<my:group4>
<my:field5>one</my:field5>
<my:field6></my:field6>
<my:field7></my:field7>
</my:group4>
<my:group4>
<my:field5>two</my:field5>
<my:field6></my:field6>
<my:field7></my:field7>
</my:group4>
<my:group4>
<my:field5>three</my:field5>
<my:field6></my:field6>
<my:field7></my:field7>
</my:group4>
</my:group3>
</my:fields>
You will need to use an xpath to select the repeating rows. It should
look
something like /my:fields/my:group

This should return a node iterator that you can use to walk over each
row
and insert each row into the database.

I would recommend you build a sample application and start using the
System.Xml namespace to learn more about manipulating XML through
code.

Don Reamey
Software Development Engineer
Microsoft

:

Thanks for your response Don.

My web service simply inserts data into the tables of the Access
database. I
have tried 'using Microsoft.Office.InfoPath' to enable iterating
repeating
sections but have always encountered a reference error even after
linking to
the Microsoft.Office.InfoPath.dll file.

How do I loop through repeating sections in the web service?

The web service is as follows:

<%@ WebService Language="C#" Class="submitForm" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.OleDb;
using System.Xml;
using System.Xml.XPath;

[WebService(Namespace = "http://localhost/submitForm")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class submitForm : WebService {

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;
Data
Source=C:\Database\DB.mdb";

public struct Details
{
public String FirstName;
public String LastName;
public DateTime DoB;

public String SupervisorName;
public DateTime SupervisedDate;
public String SupervisorPhone;
public String SupervisorEmail;

}

[WebMethod]
public void addNewDetails(Details details)
{

OleDbConnection connection = new OleDbConnection(connectionString);
OleDbCommand command = new OleDbCommand("INSERT INTO [Table1]
(FirstName,
LastName, DoB) VALUES (@FirstName, @LastName, @DoB)", connection);

command.Parameters.AddWithValue("@FirstName", details.FirstName);
command.Parameters.AddWithValue("@LastName", details.LastName);
command.Parameters.AddWithValue("@DoB", details.DoB);

command.Connection = connection;
command.Connection.Open();
command.ExecuteNonQuery();

OleDbCommand command2 = new OleDbCommand("INSERT INTO [Table2]
(SupervisorName, SupervisedDate, SupervisorPhone, SupervisorEmail)
VALUES
(@SupervisorName, @SupervisedDate, @SupervisorPhone,
@SupervisorEmail)",
connection);

command2.Parameters.AddWithValue("@SupervisorName",
details.SupervisorName);
command2.Parameters.AddWithValue("@SupervisedDate",
details.SupervisedDate);
command2.Parameters.AddWithValue("@SupervisorPhone",
details.SupervisorPhone);
command2.Parameters.AddWithValue("@SupervisorEmail",
details.SupervisorEmail);

command2.Connection = connection;
command.Connection.Close();
command2.Connection.Open();
command2.ExecuteNonQuery();
command2.Connection.Close();

}

}

:

Without seeing what your web service is doing there is not much
advice than
can be given.

I would recommend debugging your web service to see how data is
getting
inserted into a the table.

--
Don Reamey
Microsoft
Software Development Engineer
InfoPath Forms Server
http://blogs.officezealot.com/dreamey


Hi,

We have implemented an InfoPath 2007 Browser Form that submits
data
using
a
web service to an Access 2002 Database along the same lines as
S.Y.M
Wong-A-Ton's article at
http://www.bizsupportonline.net/inf...om-infopath-to-mysql-database-web-service.htm.

The issue is that only data for the form's first repeating
section
is
submitted to the database. Data for additional sections a user
adds
seem
to
get lost.

Any direction provided towards resolving this will be
appreciated.
Thank
you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top