Ok, to cut a long story short I am doing load testing so I need to add 1000+ user credentials (email, password) to the DB
. I have been using automated scripts using selenium
and c#
and would like to write a script to write this data into a csv
file. I have random generators where I can make every email unique. I guess I would need a for loop for this? Anyone got the code for this? Btw once I have the csv
file I already have a query to import the csv
file into the DB
.
So I found a script to add 2 columns but I am a total beginner so I haven't got a clue what to try, all google searches doesn't quite do what I am after even though the job should be quite simple.
public static void WriteToExcelMethod(string email, string passwd)
{
string path = @"c:\temp\MyTest.csv";
string line = String.Format(@"""{0}"",""{1}"", email, passwd);
using (StreamWriter sw = File.AppendText(path))
{
sw.WriteLine(line);
}
}
Is this a better script to write 2 columns and 1000 rows:
//before your loop
var csv = new StringBuilder();
//in your loop
var first = reader[0].ToString();
var second = image.ToString();
//Suggestion made by KyleMit
var newLine = string.Format("{0},{1}", first, second);
csv.AppendLine(newLine);
//after your loop