Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to get the correct code

how to get the correct code

Scheduled Pinned Locked Moved C#
helptutorialquestionworkspace
13 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A angels777

    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'

    A Offline
    A Offline
    angels777
    wrote on last edited by
    #3

    after included i cant find the COnfigurationManager also ... system.configuration. only have .ConfigurationSettings and .ConfigurationException

    S 1 Reply Last reply
    0
    • A angels777

      after included i cant find the COnfigurationManager also ... system.configuration. only have .ConfigurationSettings and .ConfigurationException

      S Offline
      S Offline
      Scott Dorman
      wrote on last edited by
      #4

      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]

      A 1 Reply Last reply
      0
      • S Scott Dorman

        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]

        A Offline
        A Offline
        angels777
        wrote on last edited by
        #5

        yes.. i had added.. the using System.Configuration but still don have the manager thing.

        S 1 Reply Last reply
        0
        • S Scott Dorman

          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]

          L Offline
          L Offline
          Laddie
          wrote on last edited by
          #6

          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

          S 1 Reply Last reply
          0
          • A angels777

            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'

            A Offline
            A Offline
            angels777
            wrote on last edited by
            #7

            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;

            S 1 Reply Last reply
            0
            • A angels777

              yes.. i had added.. the using System.Configuration but still don have the manager thing.

              S Offline
              S Offline
              Scott Dorman
              wrote on last edited by
              #8

              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]

              1 Reply Last reply
              0
              • L Laddie

                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

                S Offline
                S Offline
                Scott Dorman
                wrote on last edited by
                #9

                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]

                L 1 Reply Last reply
                0
                • A angels777

                  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;

                  S Offline
                  S Offline
                  Scott Dorman
                  wrote on last edited by
                  #10

                  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]

                  A 1 Reply Last reply
                  0
                  • S Scott Dorman

                    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]

                    L Offline
                    L Offline
                    Laddie
                    wrote on last edited by
                    #11

                    Yup..Sorry it is my mistake. You have already replayed it with the code block so it should help the poster now

                    Thanks Laddie Kindly rate if the answer was helpful

                    1 Reply Last reply
                    0
                    • S Scott Dorman

                      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]

                      A Offline
                      A Offline
                      angels777
                      wrote on last edited by
                      #12

                      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..

                      S 1 Reply Last reply
                      0
                      • A angels777

                        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..

                        S Offline
                        S Offline
                        Scott Dorman
                        wrote on last edited by
                        #13

                        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]

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups