我有以下代码,想知道如何让 DataColumn row[col] 浮动?
queryString = "SELECT Price FROM sampledata";
SqlCommand cmd = new SqlCommand(queryString, connection);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable("SampleTable");
sda.Fill(dt);
foreach (DataRow row in dt.Rows)
{
// this value should become float pPrice = 0;
string pPrice = "";
foreach (DataColumn col in dt.Columns)
{
if (col.ToString().Trim() == "Price")
{
// pPrice = float.Parse(row[col].ToString()) does not work
// table column from sampledata is float
pPrice = row[col].ToString();
}
}
}