sreenu kolusu

sreenu kolusu

  • NA
  • 38
  • 181k

Submitting to a Database in InfoPath Forms Services?

Aug 9 2012 2:45 PM

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

        }

Answers (1)