Click here to Skip to main content
15,884,083 members
Home / Discussions / C#
   

C#

 
GeneralCall WebApi from MVC application and pass the value to a model class Pin
Member 1396461028-Aug-18 3:55
Member 1396461028-Aug-18 3:55 
GeneralRe: Call WebApi from MVC application and pass the value to a model class Pin
Simon_Whale28-Aug-18 4:43
Simon_Whale28-Aug-18 4:43 
QuestionHow to parse certain values from an invisible cmdline Pin
wesley994626-Aug-18 5:08
wesley994626-Aug-18 5:08 
AnswerRe: How to parse certain values from an invisible cmdline Pin
Mycroft Holmes26-Aug-18 13:14
professionalMycroft Holmes26-Aug-18 13:14 
GeneralRe: How to parse certain values from an invisible cmdline Pin
wesley994626-Aug-18 13:37
wesley994626-Aug-18 13:37 
AnswerRe: How to parse certain values from an invisible cmdline Pin
OriginalGriff26-Aug-18 21:25
mveOriginalGriff26-Aug-18 21:25 
AnswerRe: How to parse certain values from an invisible cmdline Pin
Matias Lopez31-Aug-18 8:54
Matias Lopez31-Aug-18 8:54 
QuestionC# float variable are losing their decimals after being inserted on MySQL database Pin
Member 1394865826-Aug-18 2:18
Member 1394865826-Aug-18 2:18 
I've got a really weird problem here !

I've written a C# console app to get data from predefined IP addresses, after the calculations, I want the data to be inserted to a MySQL database so I can read it and do more calculations if needed using a PHP web application,

on my lap top everything is working perfectly,

when I run the C# app on the server, the data is being handled perfectly until the last step which is inserting it, but when it inserts the data, it's like an integer, no decimals.

I used VS Studio tools and tracked my variables, they are correct even in the sql statements but on the database they're losing their decimals.

I'm using windows 10 on my laptop and the server has windows Server 2016

here's the C# code :

<pre lang="c#">
public static string send_to_db(int uid, float prs, float btlvl, float f1, float f2, double t1, double t2, int dState, int supState, string datetime, string stmt)
    {
        MySqlConnection connection = null;
        string feedback = "";
        double min_prs_val = 0, max_prs_val = 0;

        // voltage to percentage the btlvl

        btlvl = (btlvl * 100) / 12;

        try
        {
            connection = new MySqlConnection(stmt);
            connection.Open();
            MySqlCommand insertData = new MySqlCommand($"INSERT INTO pm_data_records (pm_detail_id, pm_pressure, pm_battery_charge, pm_flow1, pm_flow2, pm_tot1, pm_tot2, pm_door, pm_sup, pm_sent_time) VALUES('{uid}','{prs}','{btlvl}','{f1}','{f2}','{t1}','{t2}','{dState}','{supState}','{datetime}')", connection);
            insertData.ExecuteNonQuery();
            MySqlCommand updateData = new MySqlCommand($"UPDATE pm_data_last SET pm_detail_id = '{uid}', pm_pressure = '{prs}', pm_battery_charge = '{btlvl}', pm_flow1 = '{f1}', pm_flow2 = '{f2}', pm_tot1 = '{t1}', pm_tot2 = '{t2}', pm_door = '{dState}', pm_sup = '{supState}', pm_sent_time = '{datetime}' WHERE pm_detail_id = '{uid}'", connection);
            updateData.ExecuteNonQuery();

            ...

I installed visual studio on the server and copied the code from my laptop and compiled it there too (after installing the MySQL for vs files) and still no decimals,

I'm outta ideas, help me plz ! tnx
QuestionRe: C# float variable are losing their decimals after being inserted on MySQL database Pin
Richard MacCutchan26-Aug-18 2:56
mveRichard MacCutchan26-Aug-18 2:56 
AnswerRe: C# float variable are losing their decimals after being inserted on MySQL database Pin
OriginalGriff26-Aug-18 4:04
mveOriginalGriff26-Aug-18 4:04 
AnswerRe: C# float variable are losing their decimals after being inserted on MySQL database Pin
Richard Andrew x6426-Aug-18 4:16
professionalRichard Andrew x6426-Aug-18 4:16 
AnswerRe: C# float variable are losing their decimals after being inserted on MySQL database Pin
MadMyche27-Aug-18 9:38
professionalMadMyche27-Aug-18 9:38 
GeneralRe: C# float variable are losing their decimals after being inserted on MySQL database Pin
Richard Andrew x642-Sep-18 5:20
professionalRichard Andrew x642-Sep-18 5:20 
QuestionHow to get all excel cell data and update new data under specific cell using c# Pin
Sammed24-Aug-18 2:36
Sammed24-Aug-18 2:36 
QuestionC# List<Task> Execution Order Pin
Kevin Marois23-Aug-18 8:22
professionalKevin Marois23-Aug-18 8:22 
AnswerRe: C# List<Task> Execution Order Pin
Richard Deeming23-Aug-18 8:37
mveRichard Deeming23-Aug-18 8:37 
GeneralRe: C# List<Task> Execution Order Pin
Kevin Marois23-Aug-18 9:00
professionalKevin Marois23-Aug-18 9:00 
GeneralRe: C# List<Task> Execution Order Pin
Bernhard Hiller23-Aug-18 21:40
Bernhard Hiller23-Aug-18 21:40 
QuestionUnzip file from resources Pin
JCompier21-Aug-18 19:15
JCompier21-Aug-18 19:15 
AnswerRe: Unzip file from resources Pin
OriginalGriff21-Aug-18 19:34
mveOriginalGriff21-Aug-18 19:34 
AnswerRe: Unzip file from resources Pin
Daniel Pfeffer21-Aug-18 20:52
professionalDaniel Pfeffer21-Aug-18 20:52 
GeneralRe: Unzip file from resources Pin
JCompiler22-Aug-18 2:33
JCompiler22-Aug-18 2:33 
GeneralRe: Unzip file from resources Pin
Richard Deeming22-Aug-18 2:43
mveRichard Deeming22-Aug-18 2:43 
GeneralRe: Unzip file from resources Pin
JCompiler22-Aug-18 3:05
JCompiler22-Aug-18 3:05 
GeneralRe: Unzip file from resources Pin
JCompiler22-Aug-18 4:30
JCompiler22-Aug-18 4:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.