Hi, I would like to read a single row in a csv file, the csv file is like this:
EnvironmentURL
localhost
want to read "localhost" as a parameter and pass it out, now I have this code in my program.cs but got some errors
CSVConnector csvConnector = new CSVConnector(@"..\..\EnvironmentURL.csv");
string EnvironmentURL = csvConnector.Rows["EnvironmentURL"].ToString();
the error I got was "cannot convert from sting to int"
appreciate the help.
read a single row in csv file
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: read a single row in csv file
... because you have a syntax error. The Rows property indexer takes an integer as parameter, not a string. The following code should work:lingzhou wrote:the error I got was "cannot convert from sting to int"
string EnvironmentURL = csvConnector.Rows[0].ToString();Regards,
Alex
Ranorex Support Team
Re: read a single row in csv file
Alex, thank you for the help.
The code below doesn't throw any error, but it returns EnvironmentURL equal to "system.data.datarow".
I would like EnvironmentURL to be "localhost" in this case.
The code below doesn't throw any error, but it returns EnvironmentURL equal to "system.data.datarow".
I would like EnvironmentURL to be "localhost" in this case.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: read a single row in csv file
Ahhh, now I know what you are trying to do, you are trying to get the value for EnvironmentURL from the first row. Well, that's quite simple, in your code you are simply missing the index for the row! You need to specify what row you want to get the value from like in the code below:
Alex
Ranorex Support Team
string EnvironmentURL = csvConnector.Rows[0]["EnvironmentURL"].ToString();Regards,
Alex
Ranorex Support Team
Re: read a single row in csv file
This one works perfect. Hope I can pick up C# quickly...