Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. double.tryparse()

double.tryparse()

Scheduled Pinned Locked Moved C#
databasequestionhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User3490
    wrote on last edited by
    #1

    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());

    G M 2 Replies Last reply
    0
    • U User3490

      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());

      G Offline
      G Offline
      Garth J Lancaster
      wrote on last edited by
      #2

      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'

      1 Reply Last reply
      0
      • U User3490

        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());

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups