1

Hey all I have this code:

tmpConnString = string.Format(ConfigurationManager.ConnectionStrings["devConn_HRDB"].ConnectionString, _tmpValuesBack[3], _tmpValuesBack[1], _tmpValuesBack[4], _tmpValuesBack[2]);

And its referencing this in the web.config file:

<connectionStrings>
    <add name="devConn_HRDB" connectionString="Data Source={0};User ID={1};Password={2};Initial Catalog={3};"/>
</connectionStrings>

And the error I am getting with the _tmpValuesBack[3], _tmpValuesBack1, _tmpValuesBack[4], _tmpValuesBack[2] is:

Method name expected

So I'm not really sure what its asking for there...._tmpValuesBack is defined as a string[] _tmpValuesBack = getHRPW().Split('|'); array. enter image description here

StealthRT
  • 9,252
  • 35
  • 155
  • 302
  • 2
    This should work. Can you show more complete code and the exact error? (perhaps as a screen shot?) – David Jan 29 '16 at 14:55
  • 1
    I like to divide up things sometimes when I'm stuck. Set a variable for the value from web.config separately? Debug and make sure that value and string array has values you expect? – Andy Wiesendanger Jan 29 '16 at 14:56
  • are you using string.Format or String.Format?? – apomene Jan 29 '16 at 14:57
  • 2
    @apomene [There's no difference](http://stackoverflow.com/questions/7074/whats-the-difference-between-string-and-string). – James Thorpe Jan 29 '16 at 14:57
  • What's the type of the variable _tmpValuesBack? Is it just a simple array? I think the error is on this variable, where one of them may not have any value. Could you separate each value into a string variable so that you could see how it is failing? – Batuta Jan 29 '16 at 14:59
  • @JamesThorpe Sometimes [there is](http://stackoverflow.com/q/15543841/11683) ;) – GSerg Jan 29 '16 at 15:01
  • 4
    defining _tmpValuesBack as `var _tmpValuesBack = new string[] {"zero","one","two","three","four"};` makes this work fine for me. something else is wrong, or you have a syntax error that you didn't copy into the post. – DrewJordan Jan 29 '16 at 15:01
  • @GSerg Only when the implementation is buggy :) – James Thorpe Jan 29 '16 at 15:02
  • 1
    can you post the whole file as code? And, I hate to say it, but did you try restarting VS? – DrewJordan Jan 29 '16 at 15:35
  • wow.... @DrewJordan go ahead and make that the official answer as restarting VS corrected it.... – StealthRT Jan 29 '16 at 15:37
  • that's not an answer.... I would just close your question. cheers! – DrewJordan Jan 29 '16 at 15:37
  • @DrewJordan Sure its an answer. – StealthRT Jan 29 '16 at 15:38

1 Answers1

0

Seems like that should work fine, sometimes the compiler can get messed up. Try restarting VS and see if that helps.

DrewJordan
  • 5,032
  • 1
  • 21
  • 39