How do I submit data of web-enabled form via webservice to sql - InfoPath Dev
in

InfoPath Dev

How do I submit data of web-enabled form via webservice to sql

Last post 07-01-2007 09:45 PM by stevanus.hk. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 06-04-2007 06:32 AM

    How do I submit data of web-enabled form via webservice to sql

    I have set up a web service (using Visual Studio 2005) to send data to a SQL 2005 database.

    I created a new web-enabled InfoPath Form with Submit/Receive functions. I have added a submit button to the form, and set submit up to submit to the web service.

    When I hit "Run query", Infopath successfully queries the databases and shows me its tabel entries. But when I fill in the form and submit the data, it doesn't go into the SQL database, although InfoPath tells me that is successfully submitted the data.

    What am I doing wrong?
  • 06-04-2007 10:14 AM In reply to

    Re: How do I submit data of web-enabled form via webservice to sql

    Well, if InfoPath does not complain, it looks like the problem could be on the webservice side. I would recommend attaching the VS debugger to your IIS process (it's w3wp on .NET Server/Vista, don't recall off the top of my head what it is in XP), putting a breakpoint in your webmethod and making sure it does what you expect it to do when InfoPath hits it (verify the parameters from InfoPath are what you've expected them to be).

    Good luck debugging!

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-05-2007 12:25 PM In reply to

    Re: How do I submit data of web-enabled form via webservice to sql

    Hi,

    thanks for your reply. I now found the reason but not the solution.

    In the submit webmethod of the webservice, I only updated the sqldataadapter but did not run any insert code for sql.

    The sqldataadapter already created the insert command by itself when adding the sqldataadapter to the webservice.

    But when I try to submit the data, i get the failure message :

    System.Data.SqlClient.SqlException: The parameterized query '(@Firstname nchar(4000),@Lastname nchar(4000))INSERT INTO [timet' expects the parameter '@Firstname', which was not supplied.

    Here is the WebMethod to submit to the database and the SqlInsertCommand.

    [WebMethod] // A method to expose on the Web service

    public DataSet SubmitDataSet(DataSet ds)
    {

    InitializeComponent();

    sqlConnection1.Open();

    sqlInsertCommand1.ExecuteNonQuery();

    sqlConnection1.Close();


    return ds;

    }

     


    // sqlInsertCommand1

    this.sqlInsertCommand1.CommandText = "INSERT INTO [timetrack] ([Firstname], [Lastname]) VALUES (@Firstname, @Lastname)";

    this.sqlInsertCommand1.Connection = this.sqlConnection1;

    this.sqlInsertCommand1.Parameters.AddRange(new System.Data.SqlClient.SqlParameter[] {

    new System.Data.SqlClient.SqlParameter("@Firstname", System.Data.SqlDbType.NChar, 0, "Firstname"),

    new System.Data.SqlClient.SqlParameter("@Lastname", System.Data.SqlDbType.NChar, 0, "Lastname")});

    //

    Can you see, where the failure is hidden??

    The web-form of Infopath has only two text-boxes to type in a firstname and a lastname...

    Should be a simple webservice but is already a 2 weeks project now. Would be great if you can help me find a solution.

  • 07-01-2007 09:45 PM In reply to

    Re: How do I submit data of web-enabled form via webservice to sql

    you need to pass value to your  parameter, try to create webmethod with parameter, in vb i usually create like this:

    public sub submitdata(byval firstName as string, byval lastName as string)

    'your query here'

    end sub

    in this sub you need to assign value from procedure ex firstName to your query parameter ex @firstName. because i see you didn't pass value for your sql parameter

    if this work try to open your web service and invoke that.

Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.