in

InfoPath Dev

InfoPath - Calling Stored Procedure with parameters from C#

Last post 07-01-2008 07:28 AM by Hilary Stoupa. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 06-30-2008 02:40 AM

    • zero77
    • Not Ranked
    • Joined on 06-30-2008
    • Posts 2

    InfoPath - Calling Stored Procedure with parameters from C#

    To anybody that can help,

    Objective: I want to pass through parameters to an SQL Server 2005 stored procedure from an InfoPath field.

     

    Problem: How to do this within the Change Event of the field using C# or VB?

     

    A bit of background:

    I have installed Microsoft .NET Framework 3.0 and Visual Studio

    What this means is that whenever I try to insert code into the Change Event of the field (which contains the parameter value), it loads up Microsoft Visual Basic for applications environment. I found this article which explains this:

    http://msdn.microsoft.com/en-us/library/bb250982.aspx

    Additionally, I have found this article that at first glance appears to do what I want:

    http://support.microsoft.com/kb/827007

    The problem with this is that it uses a script within Microsoft Script Editor.

    Help please

  • 06-30-2008 07:00 AM In reply to

    Re: InfoPath - Calling Stored Procedure with parameters from C#

    Have you looked at using a web service instead?

    This is best practice rather than hardcoding each InfoPath form with code.

    Qdabra has some installable ones to get you going immediatly or for reference.

    DBXL v2.2 Beta Edition

    Filed under:
  • 06-30-2008 02:26 PM In reply to

    Re: InfoPath - Calling Stored Procedure with parameters from C#

    Hello:

    Here is a link to a code sample that creates a Sql connection in code: http://www.sharepointblogs.com/ssa/archive/2006/01/03/populating-infopath-fields-with-sql-data-using-managed-code.aspx

    Where this code has the command "select * from tblUser" you could easily replace with "execute sp"  etc. If you want to get your parameter value from form field and use that value for your parameter, you can do something like this:

    string xpath = "/my:myFields/my:textField";
    XPathNavigator field = MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager);

    and then use field.Value in your sql command for your parameter value. If your form is defaulting to vb.net and you'd prefer C#, you can change that in Tools/Form Options under the programming tab.

    Hilary Stoupa / InfoPath Developer
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-30-2008 06:46 PM In reply to

    • zero77
    • Not Ranked
    • Joined on 06-30-2008
    • Posts 2

    Re: InfoPath - Calling Stored Procedure with parameters from C#

    Thanks for both your replies.

    I think I should've been clearer. 

    My problem is that I wish to create a Data Link File (so that authentication is done there). This is because I have heard that embedding the authentication within custom code raises a security issue. The following article appears to explain what i want to do. However, it does it in script and I want to do this in C#: http://support.microsoft.com/kb/827007

    I think I might just have to use a web service as was advised?

     

     

  • 07-01-2008 07:28 AM In reply to

    Re: InfoPath - Calling Stored Procedure with parameters from C#

    A web service is a great way to go, and Qdabra's DBXL can help you with this and much more. However, you can use a .config file in your C# project to store your authentication information, and call that in your code, so that you do not need to store your authentication information. This post has some information about using a .config file: http://www.infopathdev.com/forums/p/8167/29809.aspx#29809

    Hilary Stoupa / InfoPath Developer
    Qdabra® Software / Streamline data gathering to turn process into knowledge
Page 1 of 1 (5 items)
Copyright © 2003-2007 Qdabra Software. All rights reserved.
View our Terms of Use.