Inserting data back to the table

S

sadhana

Hi,
My requirement is, I have to retrieve data from a db table, and 've to
increment it by 1 and insert that into the database table.
I am able to do it through web service individually. I mean, I am able to
get the data from db and when i press submit it is going back to the table.
But I want to insert the data into table as soon as the form opened.(without
pressing submit).
I tried to write the code in the form_load event of the infopath, but it is
not working.
Can you plz help me where and how to write code for that.

Thanks
 
S

SSA

What error do you get when you try to use the formevent loading? It should be
simple. Add the DB insertion routine in the form loading event.

1. Add an event handler in the internalstartup() function:

EventManager.FormEvents.Loading += new
LoadingEventHandler(FormEvents_Loading);

2. Declare a formevents_loading function:

public void FormEvents_Loading(object sender, LoadingEventArgs e)
{

//Add your code here
}

Now, every time the form loads, a value will be entered in your DB. You may
not want to enter a value everytime, for example, if a user opens the form in
edit mode, you may not want to enter a new value if the form is in edit mode.
You can enter the following check:

if (e.InputParameters.ContainsKey("XmlLocation"))
{
//Do something else
}
else
{
//Add new value to DB
}

Put this check in the formevents_loading().

Hope this helps!

SSA
MOSS MVP
 
S

Shiva (GGK Tech)

Hi,

You can write your code in onContextChange event then form when is opened it
will submitted. But this event fires every time, changes made in Infoath form
for that one you have to set one global variable in formcode.cs. Once your
code is runs then set that global variable value is ‘true’.

You have to check condition to run your code when your global variable value
is false only.

Hope this helps you
 
S

Shiva (GGK Tech)

Hi,

You can write your code in onContextChange event then form when is opened it
will submitted. But this event fires every time, changes made in Infoath form
for that one you have to set one global variable in formcode.cs. Once your
code is runs then set that global variable value is ‘true’.

You have to check condition to run your code when your global variable value
is false only.

Hope this helps 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