none
I want to insert data from Windows Application of C# to Sql server RRS feed

  • Question

  • When run my code then show this error message "Error :The name 'ConfigurationManager' does not exist in the current context."

    How to solve this error?

    Code:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Configuration.Assemblies;
    using System.Configuration;




    namespace practice
    {
        public partial class info : Form
        {
            public info()
            {
                InitializeComponent();
            }

            private void btn_save_Click(object sender, EventArgs e)
            {
                string constr = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
                SqlConnection Con =new SqlConnection(constr);
                Con.Open();
                SqlCommand cmd =new SqlCommand();
                cmd.Connection=Con;
                cmd.CommandType=CommandType.Text;
                cmd.CommandText="insert into info values('txt_name.Text+','+txt_mail.Text') ";
                int i=cmd.ExecuteNonQuery();
                if(i>0)
                {
                    MessageBox.Show("Data save successfully");
                    
                }
                else
                {
                    MessageBox.Show("failed");
                }


               
            }

           }
        }

    Wednesday, December 4, 2013 10:43 AM

Answers

All replies

  • The ConnectionString is a tag inside your app.config.

    The ConfigurationManager is the way to acess this tag.

    Are you sure that this tag exists on your app.config ?

    Anyway you can set your  constr with your database path

    Wednesday, December 4, 2013 11:46 AM
  • Hi Malay Roy,

    Add a reference to System.Configuration to your project and then build your application.

    I hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Wednesday, December 4, 2013 2:31 PM