How to add Application name to <appSettings/>?

自作多情 提交于 2019-12-02 02:54:45

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")

Add a AppSettings section to your web.config

<appSettings>

<add key="ApplicationName" value="/website1" />

</appSettings>

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!