C# .net connection string

Hi, I have created several sites in VB, but now need to create / convert a few more to C#.
I want to link a grid view to a dataset that I have, I have done it many times in vb but never in c#.
I have set up a data connection string in the web config which works as I have tested it against an SQLdatasource component embeded into the page.
I want to do this more programatically in the source so I have taken some of my VB script and placed it trough a convertor. and got out the other side the script attached. However I get an issue
"Non-invocable member 'System.Configuration.ConfigurationManager.ConnectionStrings' cannot be used like a method." when I try to bind to the gridview.
Any suggestions
protected void Gridview1_Set()
{
      
      string connStr = ConfigurationManager.ConnectionStrings("acVitaConnectionString").ConnectionString;
    SqlConnection con = new SqlConnection(connStr);
    SqlCommand SQLCmd = new SqlCommand("SPTopProducts", con);
        SQLCmd.CommandType = CommandType.StoredProcedure;

    try
    {
        SQLCmd.Connection.Open();
        GridView1.DataSource = SQLCmd.ExecuteReader();
        GridView1.DataBind();
        SQLCmd.Connection.Close();
        SQLCmd.Connection.Dispose();
    }
    catch (Exception ex)
    {
    }
        
        
      
}

Open in new window

Simon CrippsOwnerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Om PrakashCommented:
Change
string connStr = ConfigurationManager.ConnectionStrings("acVitaConnectionString").ConnectionString;
To
string connStr = ConfigurationManager.ConnectionStrings["acVitaConnectionString"].ConnectionString;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
meetjaydeepCommented:
you can use from System.Configuration namespace
string connStr = ConfigurationSettings.AppSettings["acVitaConnectionString"];
0
Simon CrippsOwnerAuthor Commented:
did the job many thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.