double.tryparse()
-
i have the code
string query_BranchExposureFactor = "SELECT BranchExposureFactor FROM Questionnaires_Table where Branch_ID = (SELECT Branch_ID FROM [MS Access;DATABASE=" + dialog.FileName + "].Questionnaires_Table1 Where ReferenceYear = '" + txtdateref.Text + "');";
OleDbCommand cmd_BranchExposureFactor = new OleDbCommand(query_BranchExposureFactor, dbConnDest);double branchExposureFactor = (double)(cmd_BranchExposureFactor.ExecuteScalar());
i have error with double so i want to use double.tryparse() but i think that i make something wrong how can i use it in the following code ?
double branchExposureFactor = (double)(cmd_BranchExposureFactor.ExecuteScalar());
-
i have the code
string query_BranchExposureFactor = "SELECT BranchExposureFactor FROM Questionnaires_Table where Branch_ID = (SELECT Branch_ID FROM [MS Access;DATABASE=" + dialog.FileName + "].Questionnaires_Table1 Where ReferenceYear = '" + txtdateref.Text + "');";
OleDbCommand cmd_BranchExposureFactor = new OleDbCommand(query_BranchExposureFactor, dbConnDest);double branchExposureFactor = (double)(cmd_BranchExposureFactor.ExecuteScalar());
i have error with double so i want to use double.tryparse() but i think that i make something wrong how can i use it in the following code ?
double branchExposureFactor = (double)(cmd_BranchExposureFactor.ExecuteScalar());
iirc correctly, that means you'd have to get the result from your table as a string - which depends on how the table/schema is defined (you dont show this) Assuming you can get the value as a string, then
String strbranchExposureFactor = [value from DB]
Double branchExposureFactor = 0.0;
if (Double.TryParse(strbranchExposureFactor, out branchExposureFactor))
// Value is Good
else
// Value is Bad/?Out Of Range...Disclaimer : ok, Im not endorsing the 'str' prefix (whats this, Hungarian notation ?) for the String variable, use whatever your conventions dictate/allow btw http://msdn.microsoft.com/en-us/library/3s27fasw.aspx[^] and http://stackoverflow.com/questions/586436/double-tryparse-or-convert-todouble-which-is-faster-and-safer[^] 'g'
-
i have the code
string query_BranchExposureFactor = "SELECT BranchExposureFactor FROM Questionnaires_Table where Branch_ID = (SELECT Branch_ID FROM [MS Access;DATABASE=" + dialog.FileName + "].Questionnaires_Table1 Where ReferenceYear = '" + txtdateref.Text + "');";
OleDbCommand cmd_BranchExposureFactor = new OleDbCommand(query_BranchExposureFactor, dbConnDest);double branchExposureFactor = (double)(cmd_BranchExposureFactor.ExecuteScalar());
i have error with double so i want to use double.tryparse() but i think that i make something wrong how can i use it in the following code ?
double branchExposureFactor = (double)(cmd_BranchExposureFactor.ExecuteScalar());
You are really struggling with these basic concepts aren't you. Get a book and work through ALL the examples it will be ultimately quicker that repeatedly asking the same questions in a support forum. As answered the other day.
object oResult = (cmd_BranchExposureFactor.ExecuteScalar();
Now you can look at the content of oResult in your debugger to give you an idea what it contains. As Garth said it is probably a string, empy or null. Now you can deal with it!
Never underestimate the power of human stupidity RAH