Hello Everyone,
I am new member to this forum and also very new in creating InfoPath forms. Recently I created a simple infopath 2013 form using Visual Studio 2012 C# to query a oracle database, the C# code builds ok but crashes when invoked.
The code was fully tested and worked using only Visual Studio C# Web project before rolling out to InfoPath 2013. I am confused and just not sure what's wrong or what next steps should be, maybe one of the forum members have experienced the same problem and can help me with this dilemma.
Any help would be greatly appreciated,
Kind regards,
Don
using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;
using System.Data;
using System.Windows.Forms;
using Oracle.ManagedDataAccess.Client; // ODP.NET Oracle managed provider
using Oracle.ManagedDataAccess.Types;
namespace WebTestTool2
{
public partial class FormCode
{
public void InternalStartup()
{
((ButtonEvent)EventManager.ControlEvents["CTRL4_5"]).Clicked += new ClickedEventHandler(CTRL4_5_Clicked);
EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
}
public void CTRL4_5_Clicked(object sender, ClickedEventArgs e)
{
MessageBox.Show("Hello World !!!");
}
public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
string oradb = "Data Source=xxx;User Id=xxx;Password=xxx;";
OracleConnection conn = new OracleConnection(oradb); // C#
conn.Open();
//scripts to get value of Infopath field
XPathNavigator Period1 = this.MainDataSource.CreateNavigator().SelectSingleNode("//my:myFields/my:RTPA", this.NamespaceManager);
OracleParameter parm = new OracleParameter();
parm.OracleDbType = OracleDbType.Decimal;
parm.Value = Period1.Value;
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
// cmd.Parameters.Add(parm);
cmd.Parameters.Add("@Search", OracleDbType.NVarchar2).Value = Period1.Value;
cmd.CommandText = "select UPPER(CHAMELEON_COMPONENT) from TEF_Module where TICKET_ID_ = :1";
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
//scripts to set value of Infopath field
XPathNavigator P2 = this.MainDataSource.CreateNavigator().SelectSingleNode("//my:myFields/my:Component", this.NamespaceManager);
dr.Read();
P2.SetValue(dr.GetString(0));
conn.Dispose();
XPathNavigator dataSource;
dataSource = this.MainDataSource.CreateNavigator();
dataSource.SelectSingleNode(
"/my:myFields/my:Author", NamespaceManager).SetValue(this.User.UserName);
}
}
}