Xiaoliang Ma

Xiaoliang Ma

  • NA
  • 6
  • 3k

C# assign value to double list

Aug 7 2018 5:43 AM
 I have below code to add CT number into the CTlist. end up when i ran the code, CTlist[i] still = 1,  althought CT = 100(extracted from database). Any suggestion are much appreciated
 
sqlConSN.Open();
double CT1 = 1;
double CT2 = 1;
double CT3 = 1;
double CT4 = 1;
 
List<double> CTlist = new List<double>();
CTlist.Add(CT1);
CTlist.Add(CT2);
CTlist.Add(CT3);
CTlist.Add(CT4);
int d = 1;
int i = 0;
for (int n = 0; n < 10; n++)
{
String sqlSelectQueryID = ("Select * FROM tblSN WHERE ID = @ID");
SqlCommand sqlCmdIDLoad = new SqlCommand(sqlSelectQueryID, sqlConSN);
sqlCmdIDLoad.Parameters.Add("@ID", System.Data.SqlDbType.VarChar).Value = d;
SqlDataReader drIDReader = sqlCmdIDLoad.ExecuteReader();
if (drIDReader.Read())
{
string strCT = (drIDReader["TestH1"].ToString());
string strFAT = (drIDReader["TestH27"].ToString());
double CT;
double FAT;
if (Double.TryParse(strCT, out CT))
{
}
if (Double.TryParse(strFAT, out FAT))
{
}
if (FAT >= 1)
{
CTlist[i] = CT;
i++;
d++;
}
else
{
d++;
n = n - 1;
}
}
}
 

Answers (2)