Wednesday, May 2, 2012

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();
            }

        }

No comments:

Post a Comment