Willy
Willy

Reputation: 3824

C# Parsing Issue

I have a database , and I use ADO.net to get data from it , so I used a SQL Data adapter to fill my data in Datatable DT. I have an Attribute float x , I want to parse a column in my DT to float here's the code :

 foreach (DataRow row in DT.Rows)
        {

                x = float.Parse(row[6].ToString()F),

        }

it highlights the F in red and tells me The Name F does not exist in the current context syntax error , ',' expected .

thanks

Upvotes: 2

Views: 73

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726669

it tells me can't convert type object to float

Use Convert.ToSingle() method instead:

foreach (DataRow row in DT.Rows) {
    x = Convert.ToSingle(row[6]);
}

Upvotes: 1

Related Questions