how to write the value of a mysql sum in variable ?

Jadoka

New member
Joined
May 18, 2022
Messages
3
Programming Experience
Beginner
I'm a novice C# programmer. And I'm doing my first web CRUD, and in this CRUD there is a column called "salary", is there any way to add up all the values in salary and save it in a variable in C#? I would like to know how to show the value of this variable on the screen as well.
 
Are you using raw SQL queries with ADO.NET, or are you using Entity Framework?

Are you writing a console app, or a WinForms app, or a WPF app?
 
I'm going to assume that you're using ADO.NET. If you're doing CRUD operations then you should already know how to create connection and command objects. To retrieve a single value via a query, you call ExecuteScalar on your command and it will return that value as an object reference. You should cast that as the appropriate type, e.g. if you're summing 32-bit integers in the database then the value will be an int. Once you get the value and cast it as the appropriate type, you use it in the same way you would any other object of that type, so you shouldn't need our help to display it to the user, as any beginner tutorial will cover that. It has nothing at all to do with databases or data access.
 

Latest posts

Back
Top Bottom