How to add Application name to ?

后端 未结 3 425
遇见更好的自我
遇见更好的自我 2021-01-25 06:21

This is my app.config file looks like:



    
      

        
相关标签:
3条回答
  • 2021-01-25 07:06

    I have figured out the problem Myself after a lot of hair pulling and found the solution that I have changed my code in this way:

     cmd.CommandText = "INSERT INTO Users ( Username,ApplicationName,Password, 
        Email, PasswordQuestion, PasswordAnswer) VALUES(@Username,@ApplicationName,@Password,
        @Email,@PasswordQuestion,@PasswordAnswer)"
    

    And add another Param this way:

     Dim param6 As New SqlParameter()
     param6.ParameterName = "@ApplicationName"
     param6.Value = txtApplicationName.Text.Trim()
     cmd.Parameters.Add(param6)
    

    I know this not the best way If anyone found any other best solution let me know.

    0 讨论(0)
  • 2021-01-25 07:08

    Add a AppSettings section to your web.config

    <appSettings>
    
    <add key="ApplicationName" value="/website1" />
    
    </appSettings>
    
    0 讨论(0)
  • 2021-01-25 07:20

    There is a better way by using the following steps:

    1) Add a reference to System.Configuration to your application.

    2) Add the following block to your app.config file, within the configuration section:

      <appSettings>
        <add key="ApplicationName" value="/MyApplication" />
      </appSettings>
    

    3) Retrieve the value and use it where needed with the following code (example from your answer shown):

    param6.Value = System.Configuration.ConfigurationManager.AppSettings("ApplicationName")
    
    0 讨论(0)
提交回复
热议问题