how to get the correct code
-
may i know how to clear this error ? i tried use this System.Configuration.ConfigurationManager.AppSettings' but i canot find the .configurationManager.. private string sqlString = System.Configuration.ConfigurationSettings.AppSettings["connectionString"].ToString(); Warning 2 'System.Configuration.ConfigurationSettings.AppSettings' is obsolete: 'This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings'
-
after included i cant find the COnfigurationManager also ... system.configuration. only have .ConfigurationSettings and .ConfigurationException
Did you also add a "using System.Configurtion" to the file?
Scott. —In just two days, tomorrow will be yesterday. —Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[Forum Guidelines] [Articles] [Blog]
-
Did you also add a "using System.Configurtion" to the file?
Scott. —In just two days, tomorrow will be yesterday. —Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[Forum Guidelines] [Articles] [Blog]
-
Make sure you include a reference to the System.Configuration assembly in your project references.
Scott. —In just two days, tomorrow will be yesterday. —Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[Forum Guidelines] [Articles] [Blog]
-
may i know how to clear this error ? i tried use this System.Configuration.ConfigurationManager.AppSettings' but i canot find the .configurationManager.. private string sqlString = System.Configuration.ConfigurationSettings.AppSettings["connectionString"].ToString(); Warning 2 'System.Configuration.ConfigurationSettings.AppSettings' is obsolete: 'This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings'
i declare under this.. as global.. i do not want each function declare that.. namespace ttt { public class Dataaccess { private string sqlString = System.Configuration.ConfigurationSettings.AppSettings["connectionString"].ToString(); private SqlConnection cn;
-
yes.. i had added.. the using System.Configuration but still don have the manager thing.
What does your code look like? Here is a simple example:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string test = ConfigurationManager.AppSettings["test"];
}
}
}Scott. —In just two days, tomorrow will be yesterday. —Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[Forum Guidelines] [Articles] [Blog]
-
Looks like you are trying to add this line in the class level where variables are declared. Try using it insie the function / main where you require it.
Thanks Laddie Kindly rate if the answer was helpful
I think you wanted this reply to go to the original poster...
Scott. —In just two days, tomorrow will be yesterday. —Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[Forum Guidelines] [Articles] [Blog]
-
i declare under this.. as global.. i do not want each function declare that.. namespace ttt { public class Dataaccess { private string sqlString = System.Configuration.ConfigurationSettings.AppSettings["connectionString"].ToString(); private SqlConnection cn;
First, please use the "code block" tags (<pre>) with code blocks like that to preserve the formatting. Second, see my other resposne. You want your code to look something like this:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;namespace DataAccessLayer
{
public class DataAccess
{
private string connectionString;public DataAccess() { this.connectionString = ConfigurationManager.AppSettings\["connectionString"\]; // you could also use the following, which is the "more correct" way // this.connectionString = ConfigurationManager.ConnectionStrings\["connectionString"\]; } public string ConnectionString { get { return this.connectionString; } } }
}
Scott. —In just two days, tomorrow will be yesterday. —Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[Forum Guidelines] [Articles] [Blog]
-
I think you wanted this reply to go to the original poster...
Scott. —In just two days, tomorrow will be yesterday. —Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[Forum Guidelines] [Articles] [Blog]
-
First, please use the "code block" tags (<pre>) with code blocks like that to preserve the formatting. Second, see my other resposne. You want your code to look something like this:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;namespace DataAccessLayer
{
public class DataAccess
{
private string connectionString;public DataAccess() { this.connectionString = ConfigurationManager.AppSettings\["connectionString"\]; // you could also use the following, which is the "more correct" way // this.connectionString = ConfigurationManager.ConnectionStrings\["connectionString"\]; } public string ConnectionString { get { return this.connectionString; } } }
}
Scott. —In just two days, tomorrow will be yesterday. —Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[Forum Guidelines] [Articles] [Blog]
thanks for the wonderful reply... BUT .. i just cant get the $#&(#$ manager Error 3 The name 'ConfigurationManager' does not exist in the current context i had put the below script in the constructor as what u told..also added the using System.Configuration;
this.connectionString = ConfigurationManager.AppSettings["connectionString"];
but just no manager come out..
-
thanks for the wonderful reply... BUT .. i just cant get the $#&(#$ manager Error 3 The name 'ConfigurationManager' does not exist in the current context i had put the below script in the constructor as what u told..also added the using System.Configuration;
this.connectionString = ConfigurationManager.AppSettings["connectionString"];
but just no manager come out..
It still sounds like you haven't included the reference in the project. This is different than the "using" statement. In Visual Studio, expand the "References" folder of your project and make sure that you see "System.Configuration" listed. That should be all you need to do.
Scott. —In just two days, tomorrow will be yesterday. —Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[Forum Guidelines] [Articles] [Blog]