Equivalences of SETTING of Vb with C # (change connection string)

0

I keep trying to pass my code vb to , with the help of you I managed to advance a little, now I am in this situation:

mCnxSifco is the variable of my setting that stores my connection string in the project.

This is my code of VB that I need to pass to C# :

this.Item("mCnxSifco") = acCnxApp.Trim.Replace("qmasuser", acUserId);

When I do this:

this.mCnxSifco =acCnxApp.Trim.Replace("qmasuser", acUserId);

I mark an error that is only read or that there must be a variable on the left, and I only need to replace the new string that forms in the setting variable.

Thanks

    
asked by alfredo.avmb 23.06.2017 в 07:57
source

2 answers

0

Trim() is a method and you're using it as a field / property.

Try it this way:

this.mCnxSifco =acCnxApp.Trim().Replace("qmasuser", acUserId);
    
answered by 23.06.2017 / 14:27
source
1

Here is an example of how you can change the value of your connection string when you have declared it in the settings:

var assembly = Assembly.GetExecutingAssembly();
        var path = assembly.Location;

        Configuration config = ConfigurationManager.OpenExeConfiguration(path);
        config.ConnectionStrings.ConnectionStrings["WindowsFormsApp1.Properties.Settings.CadenaConexion"]
            .ConnectionString = "Nueva cadena"; 
        config.Save();

I hope it helps you.

    
answered by 23.06.2017 в 10:57