Submitting to a Database in InfoPath Forms Services?
public void CTRL5_5_Clicked(object sender, ClickedEventArgs e)
{
// Write your code here.
SqlConnection con = new SqlConnection("Data Source=192.168.0.11;Initial Catalog=SampleDB;User ID=sa;Password=@System12");
XPathNavigator mypath = this.CreateNavigator();
string strname = mypath.SelectSingleNode("/my:myFields/my:txtname", NamespaceManager).Value;
string strloc = mypath.SelectSingleNode("/my:myFields/my:txtlocation", NamespaceManager).Value;
string strdept = mypath.SelectSingleNode("/my:myFields/my:txtdept", NamespaceManager).Value;
string strsql = "insert into employee values('"+strname+"','"+strloc+"','"+strdept+"')";
SqlCommand cmd = new SqlCommand(strsql, con);
try
{
con.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("save successfully");
}
catch (SqlException ex)
{
MessageBox.Show("Not Saved" + ex.Message);
}
finally
{
con.Close();
}
}

Mahalingam sPosted Aug 28, 2012, 7:57 AM
Submit form data to a Microsoft SQL Server database
Overview
When you design a form template that is based on a Microsoft SQL Server database, the Data Connection Wizard enables a submit data connection to the database if the following conditions are met:
If the database meets these requirements, InfoPath enables the submit data connection and adds a Submitbutton to the Standard toolbar and a Submit command to the File menu on the form.
You can choose to disable the submit data connection in the wizard when you design a form template that is based on a database. If you disable the submit data connection in the wizard and then later you decide that you want to use this submit data connection, you can enable the submit data connection by modifying the main data connection. This article discusses how to enable that submit data connection.
NOTE You can have a submit data connection only in the main data connection to a database. You cannot add a submit data connection to the form template that is a secondary data connection to a database. If you want to use a submit data connection to a database as a secondary data connection, use a Web service that works with the database, and then add a submit data connection to that Web service.
After you enable the submit data connection, you can also customize the submit options for your form template in the following ways:
Step 1: Enable the submit data connection
Step 2: Configure the submit options
After you enable the submit data connection, InfoPath adds the Submit button to the Standard toolbar and theSubmit command to the File menu. InfoPath also configures the forms that are based on this form template to display a message to users after they submit their completed forms. The message states whether the form was successfully submitted. By default, InfoPath also keeps the forms open after users submit them. To change the text that appears on the Submit button, as well as the behavior that occurs after users submit their forms, do the following:
To change the name of the Submit button that appears on the Standard toolbar and the Submit command that appears on the File menu when users fill out the form, type the new name in the Caption box in theSubmit Options dialog box.
TIP If you want to assign a keyboard shortcut to this button and command, type an ampersand (&) before the character that you want to use as a keyboard shortcut. For example, to assign ALT+B as the keyboard shortcut for the Submit button and command, type Su&bmit.
By default, after users submit a form, InfoPath keeps the form open and displays a message to indicate if the form was successfully submitted. To change this default behavior, click Advanced, and then do one of the following:
TIP Use a message in the On failure box to tell users what to do if they cannot submit their form. For example, you can suggest that users save their form and contact someone for further instructions.