Reputation: 3168
I have below string
string str= "Insert into " + tname + "(id, t, v) values(" + lc+ ", " + mc+ ", " + rc+");" + Environment.NewLine;
and I'm write it to file:
File.AppendAllText(fileName, str);
It's working.
I also tried to use string.Join:
string str = string.Join("Insert into " + tname+ "(id, t, v) values(" + lc+ ", " + mc+ ", " + rc+ ");", Environment.NewLine);
File.AppendAllText(fileName, str);
but the file always is empty. What is wrong?
Upvotes: 0
Views: 318
Reputation: 161
i think what you need is string.Format()
string str = string.Format("Insert into {0}(id, t, v) values({1}, {2}, {3});{4}",tname, lc,mc,rc, Environment.NewLine);
Upvotes: 2
Reputation: 4679
string.Join
is to concatenate a String[]
of objects using a separator
eg
List<int> l= new List { 1,2,3 };
var s = string.Join(",",l);
s is then "1,2,3"
In your code you are basically passing in a very long separator (your string) and an empty array.
Upvotes: 0