none
How to save int value from database as int in C# code RRS feed

  • Question

  • SqlConnection sqlcon = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Ziga\Desktop\WindowsFormsApp7\loginDB.mdf;Integrated Security=True;Connect Timeout=30");
                    sqlcon.Open();
                    SqlCommand comm = new SqlCommand("Select balance from uporabniki Where uporabnisko = '" + imeu + "' and geslo = '" + geslou + "'", sqlcon);
                    SqlDataReader reader = comm.ExecuteReader();

    how can i save balance as value in c# form,

    HELP!

    Sunday, March 17, 2019 1:04 PM

Answers

  • instead of ExecuteReader()

    use

    object o = comm.ExecuteScalar();

    double result = Convert.ToDouble(o);


    • Marked as answer by Twinkiiee Sunday, March 17, 2019 4:37 PM
    Sunday, March 17, 2019 3:37 PM

All replies