How to Database on the table1 this table1 data in today date to all data and this table amount column total sum and label1 show the total amount windows form c#
Database amount show on label
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Jignesh KumarRank #91 · 22.9K reputationPosted Mar 8, 2024, 4:34 AM EST
Hello Ganesh,
using System; using System.Data.SqlClient; using System.Windows.Forms; namespace YourNamespace { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // Connection string to your SQL Server database string connectionString = @"Data Source=xyz;Initial Catalog=YourDatabaseName;User ID=sa; Password=YourPassword"; // SQL query to sum the values of a column salary from Employee table string query = "SELECT SUM(Salary) FROM Employee"; // Create a new SqlConnection using the connection string using (SqlConnection connection = new SqlConnection(connectionString)) { // Open the connection connection.Open(); using (SqlCommand command = new SqlCommand(query, connection)) { object result = command.ExecuteScalar(); if (result != null && result != DBNull.Value) { YourlabelName.Text = "Sum: " + Convert.ToString(result); } else { YourlabelName.Text = "No data found"; } } } } } }