Accessing database connection string using app.config in C# winform

前端 未结 10 1191
遇见更好的自我
遇见更好的自我 2020-12-06 00:27

I can\'t seem to be able to access the app.config database connection string in my c# winforms app.

app.config code

   
           


        
10条回答
  •  臣服心动
    2020-12-06 00:49

    The answers stating to use the line

    ConfigurationManager.ConnectionStrings["MyDBConnectionString"].ConnectionString;
    

    are correct.

    If an error appears stating that ConfigurationManager does not exist, it's because your project hasn't referenced System.Configuration.

    To do that in .NET Framework, in Solution Explorer, in the project where you want to use this line of code, right-click in References, choose Add Reference..., then choose Assemblies on the left-side and Framework under it. Pick System.Configuration on the list and click Ok.

提交回复
热议问题